WeakSet() 생성자
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
WeakSet()
생성자는 WeakSet
객체를 생성합니다.
구문
매개변수
iterable
Optional-
만약 순회 가능한 객체가 매개변수로 주어진다면, 모든 해당 객체가 새로운
WeakSet
에 추가됩니다.null
은undefined
로 취급합니다.
예제
WeakSet 객체 사용하기
js
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 를 set에서 제거
ws.has(foo); // false, foo는 이미 삭제되었습니다
ws.has(bar); // true, bar는 유지 중입니다
명심하실 점은 foo !== bar
라는 점입니다. 둘은 서로 비슷한 객체지만 같은 객체가 아닙니다. 그래서 두 객체 모두 set에 추가 가능합니다.
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakset-constructor |
브라우저 호환성
BCD tables only load in the browser