WeakSet.prototype.clear()

已废弃
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

clear() 方法用于删除 WeakSet 对象的所有元素,但是已经不是 ECMAScript 的一部分了。

语法

ws.clear();

示例

使用 clear方法

var ws = new WeakSet();

ws.add(window);
ws.has(window);  // true

ws.clear();

ws.has(window); // false

规范

没有规范或草案。该方法原本计划包括在 ECMAScript 6,但是在草案 revision 28 (October 14, 2014) 被抛弃了。浏览器原先的实现不久后也被移除了,它从来不是标准的一分子。

浏览器支持

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 36 未实现 [1] 未实现 23 未实现
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未实现 未实现 [1] 未实现 未实现 未实现

[1] Added to Firefox in version 34, but removed in version 46. See bug 1101817.

相关