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 иÑÐ»Ñ 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® 2027 Language Specification> # sec-weakmap.prototype.get> |
СовмеÑÑимоÑÑÑ Ñ Ð±ÑаÑзеÑами
Firefox-specific notes
- Prior to SpiderMonkey 38, this method threw a
TypeErrorwhen the key parameter was not an object. However, the latest ES6 standard specifies to returnundefinedinstead. Furthermore,WeakMap.prototype.getaccepted 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).