--- title: WeakMap.prototype.get() slug: Web/JavaScript/Reference/Global_Objects/WeakMap/get translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/get ---
get()
方法返回 WeakMap
指定的元素。
wm.get(key);
WeakMap
获取的元素的键。WeakMap
对象找不到这个键则返回 undefined
。get
方法
var wm = new WeakMap(); wm.set(window, "foo"); wm.get(window); // 返回 "foo". wm.get("baz"); // 返回 undefined.
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-weakmap.prototype.get', 'WeakMap.prototype.get')}} | {{Spec2('ES6')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-weakmap.prototype.get', 'WeakMap.prototype.get')}} | {{Spec2('ESDraft')}} |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 36 | {{CompatGeckoDesktop("6.0")}} | 11 | 23 | 7.1 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatGeckoMobile("6.0")}} | {{CompatNo}} | {{CompatNo}} | 8 |
undefined
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 ({{bug(1127827)}}).