Iterator/Generator methods and Iterator Generics

Yuh-Ruey Chen maian330 at
Fri Feb 2 00:10:06 PST 2007

Well, you can add reimplement all the JS1.6 array extras (filter, etc.)
on Object.prototype meaningfully (except maybe map). That would make the
"intentionally generic" methods truly be generic in practice.

The downside would be the problem that all methods share: they must be
called on some non-null value. Taking the global function approach
avoids this problem - in fact, I suspect that is why Python chose this
approach. However, syntactically the method approach looks better, e.g.
array.length reads better than len(array) IMO.

-Yuh-Ruey Chen

Brendan Eich wrote:
> On Jan 29, 2007, at 2:58 PM, TOYAMA Nao wrote:
> > JS1.7 introduced iterators/generators from Python, but it misses
> > itertools functions [1].  I suggest ES4 supports these functions as
> > methods of iterators/generators and generic methods so that they  
> > can be
> > applied to custom generators.  For example, an implementation of
> > Python's ifilter in JS1.7 can be like:
> >
> > var GeneratorPrototype = (function () { yield; })().__proto__;
> > Iterator.prototype.filter = GeneratorPrototype.filter =
> > function (callback, thisObject) {
> >   for (var i in this)
> >     if (, i, this))
> >       yield i;
> > };
> I was just working on this part of the proposal.
> In theory it is easy to add standard library methods to the spec at  
> this point if they can be expressed entirely in the new language.  In  
> practice we are saying "no new features", especially to features that  
> refract through the type system and runtime semantics.
> However, I think the ML- and Haskell-inspired itertools from Python  
> have no such effects, and should be considered for inclusion in the  
> standard library specified by ES4, so we don't have to re-standardize  
> them later after shipping them in Firefox N+1 without a spec ;-).
> But I do not believe they should be fixed or prototype methods of  
> nominal types (classes). Rather, they should simply be generic  
> functions in the iterator namespace, (e.g. iterator::zip or use  
> namespace iterator; ... zip(...)).
> With Array and String, ES1-3 stipulated generic prototype methods,  
> making for awkwardness when applying to other kinds of objects. For  
> ES4, as in JS1.6+, we are reflecting these as static generic methods  
> on their classes, simply using the classes as namespaces.  With the  
> iterator namespace, we can do better and simply write functions.   
> That's what zip, etc., are -- they are not methods.
> Thanks for your timely mail.  Comments welcome.
> /be
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at

More information about the Es4-discuss mailing list