JavaScript WeakSet delete() 方法
JavaScript WeakSet delete() 方法用于从 WeakSet 对象中移除指定对象。
语法
delete()方法的语法如下:
WeakSetObj.delete()
JavaScript WeakSet delete() 方法示例
让我们来看一个示例,删除 WeakSet 对象中的特定元素。
<script>
var ws = new WeakSet();
var obj={};
ws.add(obj);
document.writeln("Element present before invoking delete() method: "+ws.has(obj)+"<br>");
ws.delete(obj);
document.writeln("Element present before invoking delete() method: "+ws.has(obj));
</script>
输出:
Element present before invoking delete() method: true
Element present after invoking delete() method: false