Last Updated: February 25, 2016
·
1.143K
· martin_sunset

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.

2 Responses
Add your response

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 ·