WeakMap.prototype.get()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
get()
메서드는 WeakMap
객체에서 특정 요소를 반환합니다.
시도해보기
const weakmap1 = new WeakMap();
const object1 = {};
const object2 = {};
weakmap1.set(object1, 42);
console.log(weakmap1.get(object1));
// Expected output: 42
console.log(weakmap1.get(object2));
// Expected output: undefined
구문
js
get(key);
매개변수
key
-
필수로 요구되며,
WeakMap
객체에서 반환할 요소의 키입니다.
반환 값
WeakMap
객체의 특정 키와 연결된 요소입니다. 키를 찾을 수 없으면 undefined
가 반환됩니다.
예제
get() 메서드 사용하기
js
const wm = new WeakMap();
wm.set(window, "foo");
wm.get(window); // "foo" 반환.
wm.get("baz"); // undefined 반환.
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakmap.prototype.get |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
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.