Set[Symbol.species]
accessor property returns the
Set
构造函数。
The species accessor property returns the default constructor for
Set
objects. Subclass constructors may override it to change the constructor assignment.
The species property returns the default constructor function, which is the
Set
constructor for
Set
对象:
Set[Symbol.species]; // function Set()
In a derived collection object (e.g. your custom set
MySet
), the
MySet
species is the
MySet
constructor. However, you might want to overwrite this, in order to return parent
Set
objects in your derived class methods:
class MySet extends Set {
// Overwrite MySet species to the parent Set constructor
static get [Symbol.species]() { return Set; }
}
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'get Set [ @@species ]' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@species
|
Chrome 51 | Edge 13 | Firefox 41 | IE No | Opera 38 | Safari 10 | WebView Android 51 | Chrome Android 51 | Firefox Android 41 | Opera Android 41 | Safari iOS 10 | Samsung Internet Android 5.0 |
nodejs
6.5.0
|
完整支持
不支持
用户必须明确启用此特征。
Set
Set.prototype.size
get Set[@@species]
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()