Specifics of `class` and `super`

2013-12-09 Thread James Long
Hey guys, First posting to this mailing list. I'm defining a few ES6 features as sweet.js macros so existing projects can easily leverage them. I also happen to think macros are a big deal for JS and this is how future extensions should be defined... (at least ones that are mostly syntactic) My

Re: Specifics of `class` and `super`

2013-12-09 Thread Jonathan Barronville
Hi James. Take a look here:  https://people.mozilla.org/~jorendorff/es6-draft.html#sec-runtime-semantics-makesuperreference-propertykey-strict . I think that should help you. - Jonathan Barronville On December 9, 2013 at 10:54:54 AM, James Long (longs...@gmail.com) wrote: Hey guys, First

Re: Specifics of `class` and `super`

2013-12-09 Thread Allen Wirfs-Brock
super is lexically scoped, just like this to the closest enclosing function that defines it. All function definition forms except for arrow functions introduce new this/super bindings so we can just stay that this/super binds according to the closest enclosing non-arrow function definition.

Re: Specifics of `class` and `super`

2013-12-09 Thread James Long
So essentially super is an alias for `Object.getPrototypeOf(this)` ? I'm trying to interpret the spec but I'm somewhat new to the terms it uses. Not exactly sure home is, but I'm sure it's defined elsewhere in there so I'll keep digging into it. - James On Mon, Dec 9, 2013 at 10:22 AM, Allen

Re: Specifics of `class` and `super`

2013-12-09 Thread Allen Wirfs-Brock
On Dec 9, 2013, at 8:46 AM, James Long wrote: So essentially super is an alias for `Object.getPrototypeOf(this)` ? I'm trying to interpret the spec but I'm somewhat new to the terms it uses. Not exactly sure home is, but I'm sure it's defined elsewhere in there so I'll keep digging into it.

Re: Specifics of `class` and `super`

2013-12-09 Thread Brendan Eich
OnMon, Dec 9, 2013 at 10:22 AM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: super is lexically scoped This is true. James Long wrote: So essentially super is an alias for `Object.getPrototypeOf(this)` ? But |this| is not lexically scoped, so your question's answer must be no.

Re: Specifics of `class` and `super`

2013-12-09 Thread James Long
I read Allen's email wrong, thought it implied `this` was lexically scoped (which I know is not true. very little sleep at an airport...). I'll keep digging through the spec, but if someone has a quick example what ES5 code I could compile to for roughly the same semantics, that would be helpful.

Re: Specifics of `class` and `super`

2013-12-09 Thread Till Schneidereit
You could also check the output of Traceur and TypeScript. I don't know how close either of them are to implementing the exact semantics of ES6 classes, but I'm sure it'll be helpful in any case. On Mon, Dec 9, 2013 at 6:28 PM, James Long longs...@gmail.com wrote: I read Allen's email wrong,

Re: Specifics of `class` and `super`

2013-12-09 Thread Axel Rauschmayer
`super.foo(x)` is equivalent to ```js Object.getPrototypeOf(me.[[HomeObject]]).foo.call(this, x); ``` (where `me` refers to the current function) On Dec 9, 2013, at 18:28 , James Long longs...@gmail.com wrote: I'll keep digging through the spec, but if someone has a quick example what ES5

Re: Specifics of `class` and `super`

2013-12-09 Thread Juan Ignacio Dopazo
On Mon, Dec 9, 2013 at 2:36 PM, Till Schneidereit t...@tillschneidereit.net  wrote: You could also check the output of Traceur and TypeScript. I don't know how close either of them are to implementing the exact semantics of ES6 classes, but I'm sure it'll be helpful in any case. Yup. See 

Re: Specifics of `class` and `super`

2013-12-09 Thread Erik Arvidsson
TS is known to get this wrong in the name of simplicity. Traceur gets it right inside class bodies. We do not support toMethod (not even sure if this is doable). https://github.com/google/traceur-compiler/blob/master/test/feature/Classes/SuperChangeProto.js http://goo.gl/0kV4ts On Mon, Dec

Re: Specifics of `class` and `super`

2013-12-09 Thread James Long
If you have an inner function that calls `super`, Traceur keeps track of the outer this and makes sure to call it with that. TypeScript does not do this. Is this correct? ``` class Bar extends Foo { nestedFunction() { function run() { return super.getX(); }

Re: Specifics of `class` and `super`

2013-12-09 Thread Erik Arvidsson
super is lexically bound. On Mon, Dec 9, 2013 at 7:39 PM, James Long longs...@gmail.com wrote: If you have an inner function that calls `super`, Traceur keeps track of the outer this and makes sure to call it with that. TypeScript does not do this. Is this correct? TypeScript, also does not