Disallow Iterator (no-iterator)

The __iterator__ property was a SpiderMonkey extension to JavaScript that could be used to create custom iterators that are compatible with JavaScript’s for in and for each constructs. However, this property is now obsolete, so it should not be used. Here’s an example of how this used to work:

Foo.prototype.__iterator__ = function() {
    return new FooIterator(this);

You should use ECMAScript 6 iterators and generators instead.

Rule Details

This rule is aimed at preventing errors that may arise from using the __iterator__ property, which is not implemented in several browsers. As such, it will warn whenever it encounters the __iterator__ property.

The following patterns are considered problems:

/*eslint no-iterator: 2*/

Foo.prototype.__iterator__ = function() { /*error Reserved name '__iterator__'.*/
    return new FooIterator(this);

foo.__iterator__ = function () {};        /*error Reserved name '__iterator__'.*/

foo["__iterator__"] = function () {};     /*error Reserved name '__iterator__'.*/

The following patterns are not considered problems:

/*eslint no-iterator: 2*/

var __iterator__ = foo; // Not using the `__iterator__` property.

Further Reading


This rule was introduced in ESLint 0.0.9.