Function declarations with lexical `this`?
Axel Rauschmayer
axel at rauschma.de
Mon Jun 24 16:46:48 PDT 2013
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. I also wouldn’t want to lose the symmetry function declaration/generator declaration and method definition/generator method definition.
IMO, we need a consistent story for ES6 in this area.
Axel
--
Dr. Axel Rauschmayer
axel at rauschma.de
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130625/59d101e6/attachment.html>
More information about the es-discuss
mailing list