<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script> 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; this.say = function () { // stu.say = function () {} console.log(this.name, this.age); } // return this; } function Student(myName, myAge, myScore) { //let stu=new Object(); //let this=stu; Person.call(this,myName,myAge); this.score=myScore; this.study=function() { console.log("day day up"); } //return this; } let stu=new Student("cyg",66,666); // stu.name = "zs"; //stu.age = 18; //stu.score = 99; //console.log(stu.score); stu.say(); stu.study(); </script> </body> </html>
JS中继承方式2
关注
打赏