WeakMap.prototype.delete()

WeakMap 实例的 delete() 方法从此 WeakMap 中删除指定元素。

¥The delete() method of WeakMap instances removes the specified element from this WeakMap.

Try it

语法

¥Syntax

js
weakMapInstance.delete(key)

参数

¥Parameters

key

要从 WeakMap 对象中删除的元素的键。

返回值

¥Return value

true(如果 WeakMap 对象中的元素已成功删除)。如果在 WeakMap 中找不到密钥,则为 false。如果 key 不是对象或 未注册符号,则始终返回 false

¥true if an element in the WeakMap object has been removed successfully. false if the key is not found in the WeakMap. Always returns false if key is not an object or a non-registered symbol.

示例

¥Examples

使用 delete()方法

¥Using the delete() method

js
const wm = new WeakMap();
wm.set(window, "foo");

wm.delete(window); // Returns true. Successfully removed.

wm.has(window); // Returns false. The window object is no longer in the WeakMap.

规范

Specification
ECMAScript Language Specification
# sec-weakmap.prototype.delete

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also