yield and new : SpiderMonkey and the draft Spec

John J. Barton johnjbarton at johnjbarton.com
Tue Mar 15 11:13:24 PDT 2011

On 11:59 AM, Dmitry A. Soshnikov wrote:
> Moreover, forgot to mention. Passing the generator function 
> ("g-function" and "g-object" for shortness) as an argument for the 
> `Generator` constructor is not good for dynamically bound `this` value 
> (notice, that in Python's `self` is just a casual variable/argument, 
> which should be passed manually anyway).
> I.e. we should have `this` as `foo` in the following example:
> let foo = {
>   bar: function () {
>     yield (this == foo);
>   }
> };
> let g = new Generator(foo.bar);
> g.next(); // false
g.next.apply(foo,[]);  // true
> However,
> let g = foo.bar();
> g.next(); // true
Could you please explain the reasoning here? I can't figure it out. To 
me, g.next() has to mean that in "next", this===g. I can't see a path to 
conclude that foo is involved. It's only role is to hold the property 
'bar' which is a function constructing 'g'.

> But I don't see a big need in such a wrapper. If the rules are 
> specified, there should be no any confusion with using call expression 
> for getting g-object, and then use `next` to executed the continuation.
Perhaps we need a little user testing to see whose claims hold up.


More information about the es-discuss mailing list