set.@@iterator
@@iterator
属性的初始值与values
属性的初始值是相同的函数对象。
句法
mySet[Symbol.iterator]
返回值
该Set
迭代器功能,这是values()
默认功能。
例子
运用 [@@iterator]()
var mySet = new Set();
mySet.add('0');
mySet.add(1);
mySet.add({});
var setIter = mySet[Symbol.iterator]();
console.log(setIter.next().value); // "0"
console.log(setIter.next().value); // 1
console.log(setIter.next().value); // Object
使用[@@iterator]()
与for..of
var mySet = new Set();
mySet.add('0');
mySet.add(1);
mySet.add({});
for (var v of mySet) {
console.log(v);
}
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Set.prototype@@iterator' in that specification. | Standard | Initial definition. |
ECMAScript 2017 Draft (ECMA-262)The definition of 'Set.prototype@@iterator' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | 36 (36) 1 | No support | No support | No support |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 36.0 (36) 1 | No support | No support | No support |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com