mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-10-05 09:49:11 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
45 lines
1.5 KiB
Markdown
45 lines
1.5 KiB
Markdown
# 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:
|
|
|
|
```js
|
|
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.
|
|
|
|
Examples of **incorrect** code for this rule:
|
|
|
|
```js
|
|
/*eslint no-iterator: "error"*/
|
|
|
|
Foo.prototype.__iterator__ = function() {
|
|
return new FooIterator(this);
|
|
};
|
|
|
|
foo.__iterator__ = function () {};
|
|
|
|
foo["__iterator__"] = function () {};
|
|
|
|
```
|
|
|
|
Examples of **correct** code for this rule:
|
|
|
|
```js
|
|
/*eslint no-iterator: "error"*/
|
|
|
|
var __iterator__ = foo; // Not using the `__iterator__` property.
|
|
```
|
|
|
|
## Further Reading
|
|
|
|
* [MDN - Iterators and Generators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators)
|
|
* [ECMAScript 6 compatibility table - Iterators](https://kangax.github.io/es5-compat-table/es6/#Iterators)
|
|
* [Deprecated and Obsolete Features](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Deprecated_and_obsolete_features#Object_methods)
|