I'm implementing a basic "shopping Cart" where you can change product and it recalculates the total price.
I would like to access both the instance and jQuery's this instance within the same method, in particular product_change().
class Cart
constructor: ->
@bind_listeners()
bind_listeners: ->
$('td.product').on 'change', 'select',@product_change
update_prices: ->
# For each row of items get span.subtotal and sum
# Replace content of "total" field with result
product_change: ->
# Get new product's price. I need jQ's 'this'
new_price = $(this).find ':selected'
# Replace subtotal field
$('span.subtotal').html new_price
# Update all prices. I need instance's 'this'
@update_prices()
My working solution right now is to call update_prices as another binded method to the change event, using fat arrow =>. However I'd rather have a prettier alternative.
class Cart
constructor: ->
@bind_listeners()
bind_listeners: ->
$('td.product').on 'change', 'select',@product_change
# Call update_prices here
$('td.product').on 'change', 'select',@update_prices
update_prices: ->
# For each row of items get span.subtotal and sum
# Replace content of "total" field with result
product_change: ->
# Get new product's price. I need jQ's 'this'
new_price = $(this).find ':selected'
# Replace subtotal field
$('span.subtotal').html new_price
# Update all prices. I need instance's 'this'
#@update_prices()