Czytam, nie wiem. JS: ES6 & Dalej i ja natknąłem się na ten fragment w dziale Symbol.species.Co to oznacza w tym fragmencie kodu?
class Cool {
// defer `@@species` to derived constructor
static get [Symbol.species]() { return this; }
again() {
return new this.constructor[Symbol.species]();
}
}
class Fun extends Cool {}
class Awesome extends Cool {
// force `@@species` to be parent constructor
static get [Symbol.species]() { return Cool; }
}
var a = new Fun(),
b = new Awesome(),
c = a.again(),
d = b.again();
c instanceof Fun; // true
d instanceof Awesome; // false
d instanceof Cool; // true
Wydaje się, że Symbol.species funkcyjnych} {return Coś zawsze powinien zwrócić funkcji konstruktora. Ale w pierwszej obecności tej funkcji: static get [Symbol.species]() { return this; }
Jestem zdezorientowany, ponieważ zawsze uważam, że powinien to być obiekt zamiast funkcji konstruktora. Czy możesz mi pomóc wyjaśnić fakty?
Co do tego, o czym tutaj mowa?