WeakSet.prototype.delete()

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

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

Try it

语法

¥Syntax

js
weakSetInstance.delete(value)

参数

¥Parameters

value

要从 WeakSet 对象中删除的值。

返回值

¥Return value

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

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

示例

¥Examples

使用 delete()方法

¥Using the delete() method

js
const ws = new WeakSet();
const obj = {};

ws.add(window);

ws.delete(obj); // Returns false. No obj found to be deleted.
ws.delete(window); // Returns true. Successfully removed.

ws.has(window); // Returns false. The window is no longer present in the WeakSet.

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看