A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/WeakSet below:

WeakSet() æž„é€ å‡½æ•° - JavaScript

WeakSet() 构造函数

Baseline Widely available

WeakSet() 构造函数创建 WeakSet 对象。

语法
new WeakSet()
new WeakSet(iterable)

备注: WeakSet() 构造函数只能使用 new 调用。不使用 new 而直接调用会抛出 TypeError。

参数
iterable 可选

如果传入了一个可迭代对象,这个对象的所有元素都会被添加到新的 WeakSet 对象中。null 会被视为 undefined。

示例 使用 WeakSet 对象
const ws = new WeakSet();
const foo = {};
const bar = {};

ws.add(foo);
ws.add(bar);

ws.has(foo); // true
ws.has(bar); // true

ws.delete(foo); // 将 foo 从集合中移除
ws.has(foo); // false,foo 已经被移除
ws.has(bar); // true,bar 被保留

请注意 foo !== bar。它们是相似的对象,但它们不是同一个对象。因此,它们都会被添加到集合中。

规范 浏览器兼容性 参见

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4