Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

WeakMap.prototype.get()

这篇翻译不完整。请帮忙从英语翻译这篇文章

get() 返回  WeakMap 指定的元素。

语法

wm.get(key);

参数

key
必须。 想要从 WeakMap 获取的元素的键。

返回值

返回与指定键相关联的值,如果 WeakMap 对象找不到这个键则返回 undefined

例子

使用 get 方法 

var wm = new WeakMap();
wm.set(window, "foo");

wm.get(window); // Returns "foo".
wm.get("baz");  // Returns undefined.

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
WeakMap.prototype.get
Standard Initial definition.
ECMAScript 2017 Draft (ECMA-262)
WeakMap.prototype.get
Draft  

浏览器兼容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 36 6.0 (6.0) 11 23 7.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未实现 6.0 (6.0) 未实现 未实现 8

Firefox-specific notes

  • Prior to SpiderMonkey 38 (Firefox 38 / Thunderbird 38 / SeaMonkey 2.35), this method threw a TypeError when the key parameter was not an object. However, the latest ES6 standard specifies to return 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).

相关链接

文档标签和贡献者

 此页面的贡献者: Cattla, legend80s
 最后编辑者: Cattla,