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/map/@@species/index.html | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/map/@@species/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/map/@@species/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/map/@@species/index.html b/files/zh-cn/web/javascript/reference/global_objects/map/@@species/index.html new file mode 100644 index 0000000000..ded2acd30b --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/map/@@species/index.html @@ -0,0 +1,67 @@ +--- +title: 'get Map[@@species]' +slug: Web/JavaScript/Reference/Global_Objects/Map/@@species +translation_of: Web/JavaScript/Reference/Global_Objects/Map/@@species +--- +
{{JSRef}}
+ +

 Map[@@species] 访问器属性会返回一个 Map 构造函数.

+ +

语法

+ +
Map[Symbol.species]
+
+ +

描述

+ +

The species accessor property returns the default constructor for Map objects. Subclass constructors may over-ride it to change the constructor assignment.

+ +

案例

+ +

The species property returns the default constructor function, which is the Map constructor for Map objects:

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

In a derived collection object (e.g. your custom map MyMap), the MyMap species is the MyMap constructor. However, you might want to overwrite this, in order to return parent Map objects in your derived class methods:

+ +
class MyMap extends Map {
+  // 重写覆盖 MyMap species to the parent Map constructor
+  static get [Symbol.species]() { return Map; }
+}
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES2015', '#sec-get-map-@@species', 'get Map [ @@species ]')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-get-map-@@species', 'get Map [ @@species ]')}}{{Spec2('ESDraft')}} 
+ +

浏览器兼容性

+ +
+ + +

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

+
+ +

相关链接

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