Fat arrow functions in Javascript
robcee.net
Fat arrow functions in Javascript
1–10 of 48 posts
Re: Fat arrow functions in Javascript
#2Re: Fat arrow functions in Javascript
#3Is this syntax part of ECMAScript 6? I.E. will it eventually be supported by all browsers?
Re: Fat arrow functions in Javascript
#4Re: Fat arrow functions in Javascript
#5Nit: technically, all Javascript functions are lexically scoped. The fat arrow permanently binds the value of "this", which is sort of like modifying the scope, but again not technically because "this" is a special keyword and not a variable.
Re: Fat arrow functions in Javascript
#6First and probably most useful is that they gain the lexical scope of the environment they’re defined in. Nit: technically, all Javascript functions are lexically scoped. The fat arrow permanently binds the value of "this", which is sort of like modifying the scope, but again not technically because "this" is a special keyword and not a variable.
Re: Fat arrow functions in Javascript
#7If you're interested in a bit more of a comprehensive overview, Nicholas Zakas previously wrote an excellent article on arrow functions :
http://www.nczonline.net/blog/2013/09/10/understanding-ecmas...
Re: Fat arrow functions in Javascript
#8I would have preferred a different function keyword that had lexical this binding.
Re: Fat arrow functions in Javascript
#9While this is pretty cool, I'm not really a fan of this. There is less to type, but I end up spending more time reading what the code is doing since there's more than one way to do it. (With optional parens, optional braces, and special syntax for returning objects in a single line). I would have preferred a different function keyword that had lexical this binding.
Re: Fat arrow functions in Javascript
#10The fat arrow seems to be primarily about easier scoping when using this - so it's trying to patch the single most broken feature a language ever had.
The existing function syntax is fine, rather just avoid using "this" at all in your code.