ES6 added fat-arrow functions (=>
), which have two major differences from normal functions:
- shorter syntax (including implicit return if you use a single-expression body)
- inherit
this
from surrounding scope
These are both very useful features, but seem to me completely separate in their value and application – sometimes I want one, or the other, or both, or neither. It seems odd that if I want to use a short-syntax function, I have to also use the this
-modifying behaviour. And vice versa. I don't see why these two capabilities are implemented as a single addition to the language.
What if I want to use a short syntax function for its implicit return and brevity (in some context where a full function (..) { return ...}
would be slightly less readable), but I want to use this
in my function to refer to the calling context? There's no way to do this.
CoffeeScript has both ->
and =>
style functions, and apparently ES6 borrowed the =>
style from there. So my question is, why didn't ES6 also borrow the ->
style?
arguments
either.this
to the closure in a full function declaration. This might not be the part you are concerned about though.