WeakMap.prototype.set()
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.
set()
메서드는 지정된 키와 값을 가진 새 요소를 WeakMap
객체에 추가합니다.
시도해보기
const weakmap1 = new WeakMap();
const object1 = {};
const object2 = {};
weakmap1.set(object1, "foo");
weakmap1.set(object2, "bar");
console.log(weakmap1.get(object1));
// Expected output: "foo"
console.log(weakmap1.get(object2));
// Expected output: "bar"
구문
js
set(key, value);
매개변수
반환 값
WeakMap
객체입니다.
예제
set() 메서드 사용하기
js
const wm = new WeakMap();
const obj = {};
// WeakMap에 새 요소를 추가합니다
wm.set(obj, "foo").set(window, "bar"); // 체인가능
// WeakMap 요소 업데이트
wm.set(obj, "baz");
명세서
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakmap.prototype.set |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
set |
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.