JS get Set[@@species]
🌙
手机阅读
本文目录结构
Set[@@species]
访问器属性返回Set
的构造函数.
语法
Set[Symbol.species]
描述
species 访问属性返回 Set
对象的默认构造函数. 子构造函数或许会重载这个属性以至改变构造函数的赋值.
示例
species 属性返回默认的构造函数, 它是Set
对象的构造函数:
Set[Symbol.species]; // function Set()
在一个派生集合对象中 (比如你自定义的MySet
集合), MySet
的species 属性 是 MySet
构造函数. 又或者, 你想要重写它, 让它能在你派生的类方法中能返回父级Set
对象:
class MySet extends Set {
// Overwrite MySet species to the parent Set constructor
static get [Symbol.species]() { return Set; }
}
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)get Set [ @@species ] | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)get Set [ @@species ] | Draft |