yield syntax (diverging from: How would shallow generators compose with lambda?)

Brendan Eich brendan at mozilla.com
Mon May 18 12:13:01 PDT 2009

On May 18, 2009, at 11:53 AM, Neil Mix wrote:

>> But for this to be true, we would need to use the direct-eval  
>> detection hack I mentioned previously.
> On the plus side, this would allow for feature detection of  
> generator support, right?  (Is there any other way to detect  
> generator support?)

In JS1.7 you could object-detect:

     if (this.Iterator) ...

or similarly.

But I'm in the midst of writing up strawman:iterators proposal that  
doesn't add Iterator to the global object (nor any __iterator__  
getter, no double underscores).

One generalized idea for object detection of keywords that could be  
used as if they named functions in code that would be work in old  

     if (Object.implementation &&  
Object.implementation.supports('yield'))) {
         function gen() { ... yield(E); .... }
     } else {
         ... do something else ...

I'm abusing Object as ES5 does, but harder, to avoid polluting the  
global object. I'm supposing Object.implementation could be useful for  
other properties than the supports method. This reads well enough,  
although its a bit long-winded altogether (but individual names are  
short enough). Comments?


More information about the es-discuss mailing list