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,
Синтаксис
wm.get(key);
Параметры
- key
-
Обязателен. Ключ элемента, который будет возвращён из объекта WeakMap.
Возвращаемое значение
Возвращает элемент по указанному ключу или undefined, если ключ не может быть найден в объекте WeakMap.
Примеры
Использование метода get
js
var 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.
Firefox-specific notes
- Prior to SpiderMonkey 38, this method threw a
TypeError
when the key parameter was not an object. However, the latest ES6 standard specifies to returnundefined
instead. Furthermore,WeakMap.prototype.get
accepted an optional second argument as a fallback value, which is not part of the standard. Both non-standard behaviors are removed in version 38 and higher (Firefox bug 1127827).