| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/WeakSet | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 9.
* Some parts of this feature may have varying levels of support.
Set .
Set , WeakSet .
WeakSet (weak). . WeakSet , .
:
. WeakSets .
.
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; // !
execRecursively((obj) => console.log(obj), foo);
WeakSet ( _refs ) .
, WeakSet Set .
WeakSet() WeakSet .
WeakSet.prototype , WeakSet .
WeakSet.prototype.constructor . WeakSet WeakSet .
WeakSet.prototype[@@toStringTag]@@toStringTag "WeakSet". Object.prototype.toString() .
WeakSet.prototype.add()WeakSet value .
WeakSet.prototype.delete()WeakSet value . WeakSet.prototype.has(value) false .
WeakSet.prototype.has()WeakSet value .
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); // set foo
ws.has(foo); // false, foo
ws.has(bar); // true, bar
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-weakset-objects |
This page was last modified on 2024 9 30 by MDN contributors.
WeakSetObject/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |