Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

WeakSet() constructor

BaselineWidely available

TheWeakSet() constructor createsWeakSet objects.

Syntax

js
new WeakSet()new WeakSet(iterable)

Note:WeakSet() can only be constructed withnew. Attempting to call it withoutnew throws aTypeError.

Parameters

iterableOptional

If aniterable object is passed, all of its elements will be added to the newWeakSet.null is treated asundefined.

Examples

Using the WeakSet object

js
const ws = new WeakSet();const foo = {};const bar = {};ws.add(foo);ws.add(bar);ws.has(foo); // truews.has(bar); // truews.delete(foo); // removes foo from the setws.has(foo); // false, foo has been removedws.has(bar); // true, bar is retained

Note thatfoo !== bar. While they are similar objects,they are notthe same object. And so they are both added to the set.

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-weakset-constructor

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp