| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/WeakSet | [Back] [Original] |
Get to know MDN better
WeakSet Set
WeakSet WeakSet
:
WeakSets
Set SameValueZero === WeakSet
WeakSet()WeakSet
WeakSet.prototype 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
WeakSet
//
function execRecursively(fn, subject, _refs = new WeakSet()) {
//
if (_refs.has(subject)) {
return;
}
fn(subject);
if (typeof subject === "object" && subject) {
_refs.add(subject);
for (const key in subject) {
execRecursively(fn, subject[key], _refs);
}
_refs.delete(subject);
}
}
const foo = {
foo: "Foo",
bar: {
bar: "Bar",
},
};
foo.bar.baz = foo; // Circular reference!
execRecursively((obj) => console.log(obj), foo);
WeakSet _refs
WeakSet Set
| ECMAScript 2027 LanguageSpecification # sec-weakset-objects |
| Web Proxy Viewer | New URL | Original Page |