将类设置为等于其他类/函数构造函数

class Person {
  constructor() {
    this.name = "Lydia"
  }
}

Person = class AnotherPerson {
  constructor() {
    this.name = "Sarah"
  }
}

const member = new Person()
console.log(member.name)

可以将类设置为等于其他类/函数构造函数。在这种情况下,将Person设置为AnotherPerson。这个构造函数的名字是Sarah,所以新的Person实例member上的name属性是Sarah。

原文地址:https://www.cnblogs.com/samsara-yx/p/12326258.html