This page was translated from English by the community.Learn more and join the MDN Web Docs community.
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 июль 2015 г..
Методset() добавляет новый элемент с указанными ключом и значением в объект WeakMap.
In this article
Синтаксис
wm.set(key, value);
Параметры
Возвращаемое значение
ОбъектWeakMap.
Примеры
>Использование методаset
js
var wm = new WeakMap();var obj = {};// Добавляет новый элемент в объект WeakMapwm.set(obj, "foo").set(window, "bar"); // chainable// Обновляет элемент в объекте WeakMapwm.set(obj, "baz");Спецификации
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-weakmap.prototype.set> |
Совместимость с браузерами
Firefox-specific notes
- Prior to Firefox 33,
WeakMap.prototype.setreturnedundefinedand was not chainable. This has been fixed (Firefox bug 1031632). The behavior can be found in Chrome/v8 as well (issue).