mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 23:44:06 +08:00
110 lines
4.4 KiB
HTML
110 lines
4.4 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<p> <code><strong>has()</strong></code> 方法根据WeakMap对象的元素中是否存在key键返回一个boolean值。</p>
|
||
<h2 id="语法">语法</h2>
|
||
<pre><code class="language-javascript"><code><em>wm</em>.has(key);</code></code></pre>
|
||
<h3 id="Parameters">Parameters</h3>
|
||
<dl>
|
||
<dt>key</dt>
|
||
<dd>必须的。用来检测WeakMap对象中是否存在元素的键为key。</dd>
|
||
</dl>
|
||
<h3 id="Return_value">Return value</h3>
|
||
<dl>
|
||
<dt>Boolean</dt>
|
||
<dd>如果指定的key存在于某个元素中则返回true,否则返回flase。</dd>
|
||
</dl>
|
||
<h2 id="例子">例子</h2>
|
||
<h3 id="使用_has方法">使用 <code>has方法</code></h3>
|
||
<pre><code class="language-javascript">var wm = new WeakMap();
|
||
wm.set(window, "foo");
|
||
|
||
wm.has(window); // returns true
|
||
wm.has("baz"); // returns false
|
||
</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-weakmap.prototype.has" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">WeakMap.prototype.has</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-weakmap.prototype.has" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">WeakMap.prototype.has</small></a></td>
|
||
<td><span class="spec-Draft">Draft</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h2 id="浏览器兼容">浏览器兼容</h2>
|
||
<p></p><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
|
||
This compatibility table still uses the old format,
|
||
because we haven't yet converted the data it contains.
|
||
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
|
||
<div class="htab">
|
||
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
|
||
<ul>
|
||
<li class="selected"><a>Desktop</a></li>
|
||
<li><a>Mobile</a></li>
|
||
</ul>
|
||
</div><p></p>
|
||
<div id="compat-desktop">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Chrome</th>
|
||
<th>Firefox (Gecko)</th>
|
||
<th>Internet Explorer</th>
|
||
<th>Opera</th>
|
||
<th>Safari</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td>36</td>
|
||
<td><a href="/en-US/Firefox/Releases/6" title="Released on 2011-08-16.">6.0</a> (6.0)</td>
|
||
<td>11</td>
|
||
<td>23</td>
|
||
<td>7.1</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div id="compat-mobile">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Android</th>
|
||
<th>Firefox Mobile (Gecko)</th>
|
||
<th>IE Mobile</th>
|
||
<th>Opera Mobile</th>
|
||
<th>Safari Mobile</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td>6.0 (6.0)</td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td>8</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<h2 id="Firefox-特有说明">Firefox-特有说明</h2>
|
||
<ul>
|
||
<li>直到SpiderMonkey 38 (Firefox 38 / Thunderbird 38 / SeaMonkey 2.35), 这个方法在key参数不是一个对象时会抛出 <a href="Reference/Global_Objects/TypeError" title="TypeError(类型错误) 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a>。它已经从版本38后按照最新版本的ES6标准修复 (<a class="external" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1127827" rel="noopener" title="FIXED: WeakMap.get, has and delete should not throw when key param is not an object">bug 1127827</a>).</li>
|
||
</ul>
|
||
<h2 id="See_also">See also</h2>
|
||
<ul>
|
||
<li><a href="Reference/WeakMap" title="此页面仍未被本地化, 期待您的翻译!"><code>WeakMap</code></a></li>
|
||
<li><a href="Reference/Global_Objects/WeakMap/set" title="set() 方法根据指定的key和value在 WeakMap对象中添加新/更新元素。"><code>WeakMap.prototype.set()</code></a></li>
|
||
<li><a href="Reference/Global_Objects/WeakMap/get" title="get() 方法返回 WeakMap 指定的元素。"><code>WeakMap.prototype.get()</code></a></li>
|
||
</ul>
|
||
</article> |