diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html b/files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html new file mode 100644 index 0000000000..9643d66bfd --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/weakmap/set/index.html @@ -0,0 +1,89 @@ +--- +title: WeakMap.prototype.set() +slug: Web/JavaScript/Reference/Global_Objects/WeakMap/set +tags: + - JavaScript + - Method + - WeakMap +translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/set +--- +<div>{{JSRef}}</div> + +<p><code><strong>set()</strong></code> 方法根据指定的<code>key</code>和<code>value在</code> <code>WeakMap</code>对象中添加新/更新元素。</p> + +<div>{{EmbedInteractiveExample("pages/js/weakmap-prototype-set.html")}}</div> + + + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>wm</em>.set(key, value);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt>key</dt> + <dd>必须的。必须是<code>对象</code>。是要在<code>WeakMap</code> 对象中添加元素的key部分。</dd> + <dt>value</dt> + <dd>必须的。任意的值。是要在<code>WeakMap</code> 对象中添加/元素的value部分。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>该<code>WeakMap</code>对象</p> + +<h2 id="例子">例子</h2> + +<h3 id="使用set方法"><code>使用set方法</code></h3> + +<pre class="brush: js">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"); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-weakmap.prototype.set', 'WeakMap.prototype.set')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>Initial definition.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-weakmap.prototype.set', 'WeakMap.prototype.set')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容">浏览器兼容</h2> + + + +<p>{{Compat("javascript.builtins.WeakMap.set")}}</p> + +<h2 id="Firefox-特殊说明">Firefox-特殊说明</h2> + +<ul> + <li>直到Firefox 33 {{geckoRelease("33")}}, <code>WeakMap.prototype.set</code> returned <code>undefined</code> 而不支持联式。它已经修复 ({{bug(1031632)}}). 这样的实现也存在于 Chrome/v8 (<a href="https://code.google.com/p/v8/issues/detail?id=3410">issue</a>).</li> +</ul> + +<h2 id="See_also">See also</h2> + +<ul> + <li>{{jsxref("WeakMap")}}</li> + <li>{{jsxref("WeakMap.prototype.get()")}}</li> + <li>{{jsxref("WeakMap.prototype.has()")}}</li> +</ul> |