前言
本文采用ES6语法说明
对代码进行了详细的标注
对原型和原型链做了解释
代码如下:
//构造人类 class People{ constructor(name){ this.name = name } eat () { console.log(`我叫'${this.name}',我喜欢吃东西`) } } // 构造了Student类并继承了People类 class Student extends People{ constructor(name,number){ // name是公用参数,可以从父亲那里继承 super(name) this.number = number } numberNo () { console.log(`我叫'${this.name}',学号为'${this.number}'`) } } //创建实例对象 let lihua = new Student('李华',1001) console.log(lihua.name) console.log(lihua.number) lihua.numberNo() lihua.eat()