Document special behavior for using fat arrows to define class methods #2492

Closed
dlee opened this Issue Aug 13, 2012 · 5 comments

5 participants

@dlee

When using fat arrows to define class methods, the resulting javascript is very specialized:

  • the binding for this is not this, it's the new instance
  • the methods are added as instance variables to the instance to achieve above effect

This is completely different from what the fat arrow means in other contexts and should be documented.

@epidemian

+1. I think the second point is especially important. I've seen some developers use the fat arrow by default for every method, as "it prevents problems with this", having no idea that the fat arrow was copying every method into every instance unnecessarily.

@jashkenas
Owner

At the moment, the documentation says:

When used in a class definition, methods declared with
the fat arrow will be automatically bound to each instance
of the class when the instance is constructed.

What would you like added to that?

@dlee

@jashkenas Ha, didn't even see that.

It wouldn't hurt to reiterate this special case under the "Classes, Inheritance, and Super" section.

Also, code examples would help greatly.

@raganwald

I notice this discussion was left 'dangling.' I'd be happy to add a code example and/or re-iterate the behaviour if there's a consensus, and/or directive from @jashkenas

@jashkenas
Owner

Sure -- I'd be happy to take a pull request with some clarification.

@jashkenas jashkenas closed this Mar 4, 2013
@vendethiel vendethiel added the doc label Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment