Map[Symbol.species]
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Map[Symbol.species]
静态访问器属性是未使用的访问器属性,指定如何复制 Map
对象。
¥The Map[Symbol.species]
static accessor property is an unused accessor property specifying how to copy Map
objects.
语法
返回值
描述
¥Description
[Symbol.species]
访问器属性返回 Map
对象的默认构造函数。子类构造函数可以重写它以更改构造函数赋值。
¥The [Symbol.species]
accessor property returns the default constructor for Map
objects. Subclass constructors may override it to change the constructor assignment.
注意:目前所有
Map
方法均未使用此属性。¥Note: This property is currently unused by all
Map
methods.
示例
普通对象中的物种
派生对象中的物种
¥Species in derived objects
在自定义 Map
子类(例如 MyMap
)的实例中,MyMap
种类是 MyMap
构造函数。但是,你可能想要覆盖它,以便在派生类方法中返回父 Map
对象:
¥In an instance of a custom Map
subclass, such as 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 {
// Overwrite MyMap species to the parent Map constructor
static get [Symbol.species]() {
return Map;
}
}
规范
Specification |
---|
ECMAScript Language Specification # sec-get-map-@@species |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also