From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/set/@@species/index.html | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/set/@@species/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/set/@@species') 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 +--- +
{{JSRef}}
+ +

Set[@@species] 访问器属性返回Set的构造函数.

+ +

描述

+ +

species 访问属性返回 Set 对象的默认构造函数. 子构造函数或许会重载这个属性以至改变构造函数的赋值.

+ +

示例

+ +

普通对象中的 Species

+ +

species 属性返回默认的构造函数, 它是Set 对象的构造函数:

+ +
Set[Symbol.species]; // function Set()
+ +

派生对象中的 Species

+ +

在一个派生集合对象中 (比如你自定义的MySet集合),  MySet 的species 属性 是 MySet 构造函数. 又或者, 你想要重写它, 让它能在你派生的类方法中能返回父级Set 对象:

+ +
class MySet extends Set {
+  // Overwrite MySet species to the parent Set constructor
+  static get [Symbol.species]() { return Set; }
+}
+ +

规范

+ + + + + + + + + + +
Specification
{{SpecName('ESDraft', '#sec-get-set-@@species', 'get Set [ @@species ]')}}
+ +

浏览器兼容性

+ +
+ + +

{{Compat("javascript.builtins.Set.@@species")}}

+
+ +

另见

+ + -- cgit v1.2.3-54-g00ecf