Irakli Gozalishvili wrote:
Few questions on this new arrow functions:

let foo = x => x * x


1. What is foo.prototype ?
2. What does new foo(y) does ?

The idea with arrow function syntax (as opposed to block-lambda revival) was to be as close to "just syntax" for functions. Obviously we've made early-error restrictions but this design goal still stands. So the answers are:

1. Same as for any user-defined function (a fresh Object instance).
2. Same as for any user-defined function.

And Object.getPrototypeOf(() => {}) === Function.prototype.

The restriction in ECMA-262 Ed. 5.1 11.4.3, "The typeof Operator", penultimate row in Table 20:

Object (native or host and does implement [[Call]])        "function"

holds, so typeof () => {} === "function".

These are functions, arrow-functions to be precise (so with new syntax and some syntactic restrictions).

3. Is there going to be equivalent of Function for arrow functions ?

No, see above.

4. Is Function.create(foo) going to work ?

Function.create is not specified and in Harmony yet, right?

5. Will foo.call, foo.apply pass in the `this` ?

Yes, see above.

/be


Regards
--
Irakli Gozalishvili
Web: http://www.jeditoolkit.com/

On Thursday, 2012-03-29 at 07:15 , Brendan Eich wrote:

This is all moot now -- see meeting notes and followups. Thin arrow is
not going to make it, we want one arrow. The |this| parameter for opting
into dynamic rather than default-lexical |this| also died. Method
definition shorthand covers the only strong use-case, as Kevin's
analysis shows.

/be

Herby Vojčík wrote:
Brendan Eich wrote:
Kevin Smith wrote:

I hate the CoffeeScript deviation, though. It's just confusing for
anyone who ever learned that fat-arrow binds |this| and thin-arrow
doesn't.


True. On the other hand, "all arrows bind |this|" is also quite simple
and easy to remember.

Yes, and I kept the part of the proposal that allows |this| as a leading
arrow formal parameter, including with parameter default value. This
suggests a slight variation on the strawman, per your suggestion:

x -> { return this.x; } // lexical this for thin arrow
x => this.x // as for fat arrow

(this, x) -> { return this.x; } // dynamic this, five letter syn-tax
(this, x) => this.x // ditto for the expression-body form

I like this very much. Clear, orthogonal, readable.
It would be nice if this could get through.

/be

Herby

P.S.: Dynamic this no-arg function could also use one-arg shorthand?

this => this.x
this -> { return this.x; }
_______________________________________________
es-discuss mailing list
[email protected] <mailto:[email protected]>
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to