WeakSet.prototype.has()
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
인스턴스의 has()
메서드는 어떤 객체가 이 WeakSet
에 있는지 여부를 가리키는 부울을 반환합니다.
시도해보기
const weakset1 = new WeakSet();
const object1 = {};
const object2 = {};
weakset1.add(object1);
console.log(weakset1.has(object1));
// Expected output: true
console.log(weakset1.has(object2));
// Expected output: false
구문
js
has(value)
매개변수
value
-
이
WeakSet
에서 존재를 시험할 값
반환 값
이 WeakSet
에서 특정 값의 요소가 존재한다면 true
를 반환하며, 그렇지 않을 경우에는 false
를 반환합니다.
value
가 객체가 아니거나 혹은 등록되지 않은 심볼일 경우 언제나 false
를 반환합니다.
예제
has()
메서드 사용하기
js
const ws = new WeakSet();
const obj = {};
ws.add(window);
ws.has(window); // true 반환
ws.has(obj); // false 반환
// 등록되지 않은 symbol 저장
const sym = Symbol("foo");
ws.add(sym);
ws.add(Symbol.iterator);
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakset.prototype.has |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
has |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.