`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");

## 规范

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

## 浏览器兼容

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

- Desktop
- Mobile

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-特殊说明

- 直到Firefox 33 (Firefox 33 / Thunderbird 33 / SeaMonkey 2.30), `WeakMap.prototype.set` returned `undefined` 而不支持联式。它已经修复 (bug 1031632). 这样的实现也存在于 Chrome/v8 (issue).

## See also

- `WeakMap`
- `WeakMap.prototype.get()`
- `WeakMap.prototype.has()`