Rule Of Thumb for => vs -> in Coffeescript
There are two preferred styles of programming in Coffeescript, closure based and class based.
In general you will use -> when using closure based style and => when using class based style, as the latter binds the this pointer to the current instance.
Also, when using => within a class be consistant, otherwise you will introduce hard to find bugs.
Written by Martin Wawrusch
Related protips
2 Responses
Or you can think of it like this,
any time you would normally do:
var that = this;
...
foo = function(){
doSomethingWith(that);
}
do this
foo = => doSomethingWith(@)
otherwise use a skinny arrow.
over 1 year ago
·
This should actually be it's own pro tip I found a lot of devs struggling with this hence the "simple" version.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
Related Tags
#coffeescript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#