blob: c8da916aac36e5fc55391a247adebc33eb820a53 (
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
|
---
title: 'get Set[@@species]'
slug: Web/JavaScript/Reference/Global_Objects/Set/@@species
tags:
- ECMAScript2015
- JavaScript
- set
translation_of: Web/JavaScript/Reference/Global_Objects/Set/@@species
---
<div>{{JSRef}}</div>
<p><code><strong>Set[@@species]</strong></code> 访问器属性返回<code>Set</code>的构造函数.</p>
<h2 id="描述">描述</h2>
<p>species 访问属性返回 <code>Set</code> 对象的默认构造函数. 子构造函数或许会重载这个属性以至改变构造函数的赋值.</p>
<h2 id="示例">示例</h2>
<h3 id="普通对象中的_Species">普通对象中的 Species</h3>
<p>species 属性返回默认的构造函数, 它是<code>Set</code> 对象的构造函数:</p>
<pre class="brush: js">Set[Symbol.species]; // function Set()</pre>
<h3 id="派生对象中的_Species">派生对象中的 Species</h3>
<p>在一个派生集合对象中 (比如你自定义的<code>MySet</code>集合), <code>MySet</code> 的species 属性 是 <code>MySet</code> 构造函数. 又或者, 你想要重写它, 让它能在你派生的类方法中能返回父级<code>Set</code> 对象:</p>
<pre class="brush: js">class MySet extends Set {
// Overwrite MySet species to the parent Set constructor
static get [Symbol.species]() { return Set; }
}</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-get-set-@@species', 'get Set [ @@species ]')}}</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<div>
<p>{{Compat("javascript.builtins.Set.@@species")}}</p>
</div>
<h2 id="另见">另见</h2>
<ul>
<li>{{jsxref("Set")}}</li>
<li>{{jsxref("Symbol.species")}}</li>
</ul>
|