mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-10 07:54:06 +08:00
53 lines
2.8 KiB
HTML
53 lines
2.8 KiB
HTML
<article id="wikiArticle">
|
||
<div><br/>
|
||
</div>
|
||
<p><code><strong>size</strong></code> 是可访问属性,用于返回 一个<a href="Reference/Map" title="此页面仍未被本地化, 期待您的翻译!"><code>Map</code></a> 对象的成员数量。</p>
|
||
<p><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/map-prototype-size.html" width="100%"></iframe></p>
|
||
<p>这个示例源码保存在GitHub:<a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a>。如果你想贡献代码,修改后在GitHub上发推送请求给我们。</p>
|
||
<p> </p>
|
||
<h2 id="描述">描述</h2>
|
||
<p>size 属性的值是一个整数,表示 Map 对象有多少个键值对。size 是只读属性,用set 方法修改size返回 undefined,即不能改变它的值。</p>
|
||
<h2 id="示例">示例</h2>
|
||
<pre><code class="language-js">var myMap = new Map();
|
||
myMap.set("a", "alpha");
|
||
myMap.set("b", "beta");
|
||
myMap.set("g", "gamma");
|
||
|
||
myMap.size // 3
|
||
</code></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><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-get-map.prototype.size" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Map.prototype.size</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td>Initial definition.</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-get-map.prototype.size" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">Map.prototype.size</small></a></td>
|
||
<td><span class="spec-Draft">Draft</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h2 id="浏览器兼容">浏览器兼容</h2>
|
||
<p>此页的兼容性表格请查阅:<a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">https://github.com/mdn/browser-compat-data</a> <br/>
|
||
如果你想更新数据,请在GitHub上给我们发推送请求。</p>
|
||
<div class="blockIndicator warning">
|
||
<p><strong>异常提醒</strong></p>
|
||
</div>
|
||
<ul>
|
||
<li>在JavaScript中直接书写Map.prototype.size可能得到以下异常:<br/>
|
||
<code>Uncaught TypeError: Method get Map.prototype.size called on incompatible receiver #<Map></code><br/>
|
||
异常原因查看:<a class="new" href="/zh-CN/docs/" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Called_on_incompatible_type</a></li>
|
||
</ul>
|
||
<h2 id="相关阅读">相关阅读</h2>
|
||
<ul>
|
||
<li><a href="Reference/Map" title="此页面仍未被本地化, 期待您的翻译!"><code>Map</code></a></li>
|
||
</ul>
|
||
</article> |