106 lines
4.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div></div>
<p><code><strong>delete()</strong></code> 方法从 <code>WeakSet 对象中</code>移除指定的元素。</p>
<h2 id="语法">语法</h2>
<pre><code class="language-javascript"><code><em>ws</em>.delete(value);</code></code></pre>
<h3 id="参数">参数</h3>
<dl>
<dt>value</dt>
<dd>必须。从 <code>WeakSet</code> 对象中移除的对象。</dd>
</dl>
<h3 id="返回值">返回值</h3>
<p>如果在 <code>WeakSet</code> 对象中成功移除元素则返回 true。如果 key 没有在 WeakSet 中<font face="Consolas, Liberation Mono, Courier, monospace">找到或者 key 不是一个对象,则返回 false。</font></p>
<h2 id="示例">示例</h2>
<h3 id="使用_delete_方法">使用 <code>delete</code> 方法</h3>
<pre><code class="language-javascript">var ws = new WeakSet();
var obj = {};
ws.add(window);
ws.delete(obj); // 返回 false。因为 obj 没有被删除
ws.delete(window); // 返回 true。成功地移除了元素
ws.has(window); // 返回 false。因为 WeakSet 中已经不存在 window 对象
</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-weakset.prototype.delete" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">WeakSet.prototype.delete</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-weakset.prototype.delete" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">WeakSet.prototype.delete</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/34" title="Released on 2014-12-01.">34</a> (34)</td>
<td><span style="color: #f00;">未实现</span></td>
<td>23</td>
<td><span style="color: #f00;">未实现</span></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>34.0 (34)</td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
<td><span style="color: #f00;">未实现</span></td>
</tr>
</tbody>
</table>
</div>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a href="Reference/Global_Objects/WeakSet" title="WeakSet 对象允许你将弱保持对象存储在一个集合中。"><code>WeakSet</code></a></li>
<li><a href="Reference/Global_Objects/WeakSet/clear" title="clear() 方法用于删除 WeakSet 对象的所有元素,但是已经不是 ECMAScript 的一部分了。"><code>WeakSet.prototype.clear()</code></a></li>
</ul>
</article>