
no-iterator
禁止使用 __iterator__
屬性
__iterator__
屬性是 JavaScript 的 SpiderMonkey 擴充功能,可用於建立與 JavaScript 的 for in
和 for each
結構相容的自訂迭代器。然而,這個屬性現在已經過時,因此不應使用。以下是如何使用它的範例:
Foo.prototype.__iterator__ = function() {
return new FooIterator(this);
}
您應該改用 ECMAScript 6 的迭代器和產生器。
規則詳細資訊
此規則旨在防止因使用 __iterator__
屬性而可能產生的錯誤,該屬性在某些瀏覽器中並未實作。因此,每當遇到 __iterator__
屬性時,它都會發出警告。
此規則的錯誤程式碼範例
在遊樂場中開啟
/*eslint no-iterator: "error"*/
= function() {
return new FooIterator(this);
};
= function () {};
= function () {};
此規則的正確程式碼範例
在遊樂場中開啟
/*eslint no-iterator: "error"*/
var __iterator__ = foo; // Not using the `__iterator__` property.
版本
此規則在 ESLint v0.0.9 中引入。
延伸閱讀

