diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/set/@@species | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/set/@@species')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/set/@@species/index.html | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/@@species/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/@@species/index.html new file mode 100644 index 0000000000..c950ccbf5a --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/set/@@species/index.html @@ -0,0 +1,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 notranslate">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 notranslate">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> |