您当前的位置: 首页 > 

暂无认证

  • 4浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JS中继承3

发布时间:2020-08-18 00:26:11 ,浏览量:4

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript"> 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; } Person.prototype.say=function() { console.log(this.name, this.age); } function Student(myName, myAge, myScore) { Person.call(this, myName, myAge); this.score = myScore; this.study = function () { console.log("day day up"); } } // 注意点: 要想使用Person原型对象中的属性和方法, 那么就必须将Student的原型对象改为Person的原型对象才可以 Student.prototype= Person.prototype;//修改student的原型对象为person的原型对象 //为了不破坏关系,得把student的构造函数指向person原型对象的constructor Student.prototype.constructor=Student; let stu = new Student("ww", 19, 99); console.log(stu.score); stu.say(); stu.study(); </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.1133s