Function declarations with lexical `this`?
Mark S. Miller
erights at google.com
Mon Jun 24 17:00:43 PDT 2013
On Mon, Jun 24, 2013 at 4:46 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
> Sorry for bringing this point up, again. It is a minor point, but details
> matter if ECMAScript 6 is supposed to feel consistent.
> In general, I like how ECMAScript 6 has evolved functions. Before,
> functions played three roles:
> 1. Constructor
> 2. Method
> 3. Non-method function (where you want lexical `this`)
> In ES6, we have classes for #1 and method definitions for #2 (in both
> object literals and class literals). Furthermore, arrow functions replace
> function expressions and have lexical `this`. What is missing is a function
> declaration with lexical `this`.
> What’s the best way to solve this and to eliminate the pitfall of dynamic
> `this` (at least for beginners)? Tell people to const-bind arrow functions?
> We’d lose hoisting, though.
yes. I don't think this will actually be a problem in practice.
> I also wouldn’t want to lose the symmetry function declaration/generator
> declaration and method definition/generator method definition.
I do sometimes wish there was a natural place to put a "*" on an arrow
function, and sometimes I don't wish it. In any case, it's not gonna happen
> IMO, we need a consistent story for ES6 in this area.
const foo = (a,b) => a+b;
That's as consistent as it is likely to get.
> Dr. Axel Rauschmayer
> axel at rauschma.de
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> es-discuss mailing list
> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss