javaScript-继承方式
作者:互联网
1.js中继承的终极方法
1.1在子类的构造函数中通过call借助父类的构造函数
1.2将子类的原型对象修改为父类的实例对象
function Person(myName,myAge) { // let per = new Object(); // let this = per; // this = stu; this.name = myName; // stu.name = myName; this.age = myAge; // stu.age = myAge; // return this; } Person.prototype.say = function () { console.log(this.name, this.age, this.score); } function Student(myName,myAge,myScore) { // let stu = new Object(); // let this = stu; Person.call(this, myName,myAge); // Person.call(stu) this.score = myScore; this.study = function () { console.log('day day up'); } // return this; } Student.prototype = new Person(); Person.prototype.constructor = Student;
标签:function,myAge,方式,Person,继承,javaScript,myName,stu,let 来源: https://www.cnblogs.com/heartY/p/15150590.html