Iterator/Generator methods and Iterator Generics

TOYAMA Nao qv6n-tym at
Mon Jan 29 14:58:22 PST 2007

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;
Iterator.filter = function (iter, callback, thisObject) {
  return, callback, thisObject);

Of course "Iterator" in above code will be "Enumerator" in ES4 as per
the iterators and generators proposal [2].


More information about the Es4-discuss mailing list