aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/weakset/clear/index.html
blob: 7d1e17ee9de54a15073b9b5655ad0e3c562f40bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
title: WeakSet.prototype.clear()
slug: Web/JavaScript/Reference/Global_Objects/WeakSet/clear
tags:
  - JavaScript
  - Method
  - WeakSet
  - 废弃
translation_of: Web/JavaScript/Reference/Global_Objects/WeakSet/clear
---
<div>{{JSRef}} {{obsolete_header}}</div>

<p><code><strong>clear()</strong></code> 方法用于删除 <code>WeakSet</code> 对象的所有元素,但是已经不是 ECMAScript 的一部分了。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><em>ws</em>.clear();</pre>

<h2 id="示例">示例</h2>

<h3 id="使用_clear方法">使用 <code>clear方法</code></h3>

<pre class="brush: js example-bad">var ws = new WeakSet();

ws.add(window);
ws.has(window);  // true

ws.clear();

ws.has(window); // false
</pre>

<h2 id="规范">规范</h2>

<p>没有规范或草案。该方法原本计划包括在 ECMAScript 6,但是在草案 revision 28 (October 14, 2014) 被抛弃了。浏览器原先的实现不久后也被移除了,它从来不是标准的一分子。</p>

<h2 id="浏览器支持">浏览器支持</h2>

<p>{{CompatibilityTable}}</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>{{CompatNo}} [1]</td>
   <td>{{CompatNo}}</td>
   <td>23</td>
   <td>{{CompatNo}}</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>{{CompatNo}}</td>
   <td>{{CompatNo}} [1]</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] Added to Firefox in version 34, but removed in version 46. See {{bug(1101817)}}.</p>

<h2 id="相关">相关</h2>

<ul>
 <li>{{jsxref("WeakSet")}}</li>
 <li>{{jsxref("WeakSet.prototype.delete()")}}</li>
</ul>