--- title: WeakMap.prototype.delete() slug: Web/JavaScript/Reference/Global_Objects/WeakMap/delete translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/delete ---
delete()
方法可以从一个 WeakMap
对象中删除指定的元素。
wm.delete(key);
如果成功删除,返回 true
,否则返回 false
。
var wm = new WeakMap(); wm.set(window, "foo"); wm.delete(window); // 返回 true,表示删除成功。 wm.has(window); // 返回 false,因为 window 对象已经被删除了。
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-weakmap.prototype.delete', 'WeakMap.prototype.delete')}} | {{Spec2('ES6')}} | Initial definition. |
{{CompatibilityTable}}
Feature | Chrome | Firefox (SpiderMonkey) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}}[1] | {{CompatGeckoDesktop("6.0")}} | 11 | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Firefox Mobile (SpiderMonkey) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatGeckoMobile("6.0")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |