yield and new : SpiderMonkey and the draft Spec

Brendan Eich brendan at mozilla.com
Mon Mar 14 13:02:37 PDT 2011


> I.e. again, what I notice (and asked), is that there's no any info in the draft spec about `this` value of the generator's context. I think it would be good to add this information.

A generator function is still a function, and |this| binding is orthogonal to yield making the surrounding function a generator:

js> function gen() { yield [this, 1]; yield [this, 2]; yield [this, 3]; }
js> var obj = {foo: gen, toString: function(){return "[obj]"}}             
js> var a = []
js> for (v in obj.foo()) a.push(v)                                        
3
js> a[0][0] === obj                                                       
true
js> a[0][0] === obj                                                       
true
js> a[1][0] === obj 
true
js> a[2][0] === obj 
true
js> a.toString()
"[obj],1,[obj],2,[obj],3"

We'll clarify this in the strawman.

/be


More information about the es-discuss mailing list