Created
March 9, 2012 14:56
-
-
Save easierbycode/2006857 to your computer and use it in GitHub Desktop.
jQuery callback bindings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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