aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/map/set
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/map/set')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/map/set/index.html97
1 files changed, 97 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/map/set/index.html b/files/zh-cn/web/javascript/reference/global_objects/map/set/index.html
new file mode 100644
index 0000000000..ae2ff00036
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/map/set/index.html
@@ -0,0 +1,97 @@
+---
+title: Map.prototype.set()
+slug: Web/JavaScript/Reference/Global_Objects/Map/set
+translation_of: Web/JavaScript/Reference/Global_Objects/Map/set
+tags:
+ - ECMAScript 2015
+ - JavaScript
+ - Map
+ - Method
+ - Prototype
+ - Reference
+browser-compat: javascript.builtins.Map.set
+---
+<p id="sect1">{{JSRef}}</p>
+
+<p><code><strong>set()</strong></code> 方法为 <code>Map</code> 对象添加或更新一个指定了键(<code>key</code>)和值(<code>value</code>)的(新)键值对。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/map-prototype-set.html")}}</div>
+
+
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox"><code><em>myMap</em>.set(key, value);</code></pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>key</dt>
+ <dd>要添加至相应 <code>Map</code> 对象的元素的键。</dd>
+ <dt>value</dt>
+ <dd>要添加至相应 <code>Map</code> 对象的元素的值。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p><code>Map</code> 对象</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="使用_set_方法">使用 <code>set</code> 方法</h3>
+
+<pre class="brush: js">var myMap = new Map();
+
+// 将一个新元素添加到 Map 对象
+myMap.set("bar", "foo");
+myMap.set(1, "foobar");
+
+// 在Map对象中更新某个元素的值
+myMap.set("bar", "baz");
+</pre>
+
+<h3 id="链式使用_set_方法">链式使用 <code>set</code> 方法</h3>
+
+<p>因为 Set() 方法返回 Map 对象本身,所以你可以像下面这样链式调用它:</p>
+
+<pre class="brush: js">// Add new elements to the map with chaining.
+myMap.set('bar', 'foo')
+ .set(1, 'foobar')
+ .set(2, 'baz');
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">状态</th>
+ <th scope="col">备注</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES2015', '#sec-map.prototype.set', 'Map.prototype.set')}}</td>
+ <td>{{Spec2('ES2015')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-map.prototype.set', 'Map.prototype.set')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td></td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("javascript.builtins.Map.set")}}</p>
+
+<h2 id="参见">参见</h2>
+
+<ul>
+ <li>{{jsxref("Map")}}</li>
+ <li>{{jsxref("Map.prototype.get()")}}</li>
+ <li>{{jsxref("Map.prototype.has()")}}</li>
+</ul>