在线文档教程

weakMap.set

weakMap.set

set()方法根据指定的key和value在WeakMap对象中添加新/更新元素。

语法

wm.set(key, value

参数

key必须的是要在WeakMap对象中添加/更新元素的key部分value必须的是要在WeakMap对象中添加/更新元素的value部分

返回值

WeakMap对象

示例

使用set方法

var wm = new WeakMap( var obj = {}; // Add new elements to the WeakMap wm.set(obj, 'foo').set(window, 'bar' // chainable // Update an element in the WeakMap wm.set(obj, 'baz'

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'WeakMap.prototype.set' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'WeakMap.prototype.set' in that specification.Draft

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support36(Yes)6.0 (6.0)11237.1

FeatureAndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo support(Yes)6.0 (6.0)No supportNo support8