构造函数
class Person{constructor(name,age){this.name=name;this.age=age;}sayHi(){console.log(`hello,${this.name},今年我${this.age}了`)}}
class类的写法等价于函数写法
function Person(name,age){this.name=name;this.age=age}Person.prototype.sayHi=function(){console.log(`hello,${this.name},今年我${this.age}了`)}var p = new Person('dong',18)
静态方法
class EventCenter {static fire() {return 'fire';}static on(){return 'on}}
继承
class Person{constructor(name,age){this.name=name;this.age=age;}sayHi(){console.log(`hello,${this.name},今年我${this.age}了`)}}class Student extends Person{constructor(name,age,score){super(name,age);this.score = score;}myScore(){console.log(`hello,${this.name},我考了${this.score}分`)}}
