arrow function syntax simplified
dmitry.soshnikov at gmail.com
Sun Apr 1 21:48:45 PDT 2012
On Apr 1, 2012, at 7:52 AM, Brendan Eich wrote:
> Dmitry Soshnikov wrote:
>> Oh, wait, just have read Crock's article on => functions. A Python's style of passing manual `this'? That's interesting (why it's not specified on the wiki?
> See http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax&rev=1332877190 -- removed by next revision:
> # 2012/03/29 06:05 show differences to current version <http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax&rev=1333001151&do=diff> strawman:arrow_function_syntax <http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax&rev=1333001151> Updates per TC39 meeting today brendan
> The optional leading |this| parameter without an Initialiser (parameter default value) was long-hand for dynamic-this binding, the "thin arrow" (->) of previous versions. We agreed with Waldemar on cutting down a list of five "iffy" design decisions, see his meeting notes. Thin-arrow and leading |this| fell quickly, and the desire for "one arrow" was clear.
> The detailed rationale for killing leading |this| is less clear, but without it we have fewer function forms as you note (not sure where your 6 count came from, but no worries). The "YAGNI" and "dynamic-this is a foot-gun" arguments favored leaving out -> or (this, arg1, ~~~ argN) syntax. These are not absolute judgments, obviously. They're KISS and "when in doubt, leave it out" relative judgments.
OK, gottcha. Thanks, Brendan.
Yes, currently avoiding leading `this' seems less confusing.
Offtopic footnote. 6 types:
1. Function Declaration (FD). Features: "hoisting", always named.
2. Function Expression (FE). Features: no "hoisting", available for immediately invoked functions (IIF).
3. Named Function Expressions (NFE). Features: no "hoisting", the same as FE actually, but because of many old (?) bugs/features, especially in IE, I put them in the separate type. Since ES5 strict they are just FE if implemented correctly.
4. Functions created via Function constructor (FF). Features: only global in the scope chain.
5. Bound functions (BF). Features: captures `this', but "dynamic" `this' in case of `new', no `prototype', no [[Scope]], no [[Construct]], but delegation to the target's, etc.
6. Arrow functions (AF). Features: captured `this', captured `this' even in case of `new'.
More information about the es-discuss