add()
方法在 WeakSet
对象的最后一个元素后添加新的对象。
ws.add(value);
WeakSet
集合中。WeakSet
对象。
add
方法var ws = new WeakSet();
ws.add(window); // 添加 window 对象进 WeakSet 中
ws.has(window); // true
// Weakset 仅取得对象作为参数
ws.add(1);
// 结果为 "TypeError: Invalid value used in weak set" 在 Chrome 浏览器中
// 并且 "TypeError: 1 is not a non-null object" 在 Firefox 浏览器中
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) WeakSet.prototype.add |
Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) WeakSet.prototype.add |
Draft |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 36 | 34 (34) | 未实现 | 23 | 未实现 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 未实现 | 34.0 (34) | 未实现 | 未实现 | 未实现 |