Questions/issues regarding generators

Allen Wirfs-Brock allen at wirfs-brock.com
Sat Mar 30 07:44:30 PDT 2013


On Mar 30, 2013, at 7:05 AM, André Bargull wrote:

>> >> The most significant change from the meeting (and it really wasn't
>> >> explicit on the whiteboard) is that generator prototypes don't have a
>> >> "constructor" property that links back to its generator function instance.
>> >>  In other words, you can't say:
>> >>
>> >> function * ofCollection() {for (i of collection) yield i};
>> >> var itr1 = ofCollection();
>> >> var itr2 = iter1.constructor();  //TypeError
>> >>
>> >
>> > That wouldn't be a type error. It would be invoking the value of the
>> > inherited generator property.
>> >
>> 
>> Sorry, "...inherited *constructor* property" that is.
> 
> But the inherited constructor property is not callable, so it's still a TypeError:

Exactly, I had assumed that was obvious from the diagram :-)

Allen
> 
>> js> function * ofCollection() {for (let i of collection) yield i};
>> js> var itr1 = ofCollection();
>> js> var itr2 = itr1.constructor();
>> uncaught exception: TypeError: object is not a function
> 
> 
> - André

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130330/53e632ea/attachment.html>


More information about the es-discuss mailing list