JavaScript WeakMap delete()方法
JavaScript WeakMap delete() 方法用于从 WeakMap 对象中删除指定的元素。
语法
delete()方法由以下语法表示:
WeakMapObj.delete()
JavaScript WeakMap delete()方法示例
让我们看一个示例来确定WeakMap对象是否包含指定的元素。
<script>
var wm = new WeakMap();
var obj1 = {};
var obj2 = {};
var obj3= {};
wm.set(obj1, 'jQuery');
wm.set(obj2, 'AngularJS');
wm.set(obj3,'Bootstrap');
document.writeln("Element present before invoking delete() method: "+ wm.has(obj1)+"<br>");
wm.delete(obj1);
document.writeln("Element present after invoking delete() method: "+wm.has(obj1));
</script>
输出:
Element present before invoking delete() method: true
Element present after invoking delete() method: false