Skip to content

noIteratorProperty (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noIteratorProperty": "error"
}
}
}
}

Disallow the use of the __iterator__ property.

__iterator__ was a non-standard property that only Firefox supported. Assigning a function to it changed which values a for...in loop produced for an object. It was never part of the JavaScript standard, and Firefox has since removed it, so no current browser or JavaScript runtime uses it. Code that relies on it silently stops working.

To make an object iterable, define a Symbol.iterator method instead, and loop over the object with for...of. The iteration protocols guide explains how this works.

The rule reports both reading and assigning __iterator__, whether the code uses a dot (foo.__iterator__) or brackets with a string (foo["__iterator__"]).

Foo.prototype.__iterator__ = function () {
return new FooIterator(this);
};
code-block.js:1:15 lint/nursery/noIteratorProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected use of the obsolete __iterator__ property.

> 1 │ Foo.prototype.__iterator__ = function () {
│ ^^^^^^^^^^^^
2 │ return new FooIterator(this);
3 │ };

ℹ __iterator__ is a non-standard extension that modern JavaScript engines no longer support.

ℹ Use Symbol.iterator to make an object iterable instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

foo.__iterator__ = function () {};
code-block.js:1:5 lint/nursery/noIteratorProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected use of the obsolete __iterator__ property.

> 1 │ foo.__iterator__ = function () {};
│ ^^^^^^^^^^^^
2 │

ℹ __iterator__ is a non-standard extension that modern JavaScript engines no longer support.

ℹ Use Symbol.iterator to make an object iterable instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

foo["__iterator__"] = function () {};
code-block.js:1:5 lint/nursery/noIteratorProperty ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ Unexpected use of the obsolete __iterator__ property.

> 1 │ foo["__iterator__"] = function () {};
│ ^^^^^^^^^^^^^^
2 │

ℹ __iterator__ is a non-standard extension that modern JavaScript engines no longer support.

ℹ Use Symbol.iterator to make an object iterable instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

// A variable named `__iterator__` isn't a property, so it's allowed.
const __iterator__ = foo;
// Brackets with a variable look up the variable's value, not a property named `__iterator__`.
foo[__iterator__];
// The standard way to make objects iterable.
Foo.prototype[Symbol.iterator] = function* () {
yield 1;
};