The initial value of the
@@iterator
property is the same function object as the initial value of the
值
特性。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
mySet[Symbol.iterator]
Set
iterator
function, which is the
values()
function by default.
[@@iterator]()
const mySet = new Set();
mySet.add('0');
mySet.add(1);
mySet.add({});
const setIter = mySet[Symbol.iterator]();
console.log(setIter.next().value); // "0"
console.log(setIter.next().value); // 1
console.log(setIter.next().value); // Object
[@@iterator]()
with
for..of
const mySet = new Set();
mySet.add('0');
mySet.add(1);
mySet.add({});
for (const v of mySet) {
console.log(v);
}
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Set.prototype[@@iterator]' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@iterator
|
Chrome 43 | Edge 12 |
Firefox
36
|
IE No | Opera 30 | Safari 9 | WebView Android 43 | Chrome Android 43 |
Firefox Android
36
|
Opera Android 30 | Safari iOS 9 | Samsung Internet Android 4.0 | nodejs 0.12 |
完整支持
不支持
见实现注意事项。
使用非标名称。
Set
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()