Skip to content

Instantly share code, notes, and snippets.

@easierbycode
Created March 9, 2012 14:56
Show Gist options
  • Save easierbycode/2006857 to your computer and use it in GitHub Desktop.
Save easierbycode/2006857 to your computer and use it in GitHub Desktop.
jQuery callback bindings
# http://coffeescriptcookbook.com/chapters/jquery/callback-bindings-jquery
# By using the fat arrow (=>) instead of the normal arrow (->) the function gets automatically bound to the object and can access the @-variable.
$ ->
class Basket
constructor: () ->
@products = []
$('.product').click (event) =>
@add $(event.currentTarget).attr 'id'
add: (product) ->
@products.push product
console.log @products
new Basket()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment