📜  js 类 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:16.559000             🧑  作者: Mango

代码示例6
class MyArray extends Array {
  // Overwrite species to the parent Array constructor
  static get [Symbol.species]() { return Array; }
}

let a = new MyArray(1,2,3);
let mapped = a.map(x => x * x);

console.log(mapped instanceof MyArray); // false
console.log(mapped instanceof Array);   // true