您当前的位置: 首页 > 

暂无认证

  • 3浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JS继承核心(1)第一种方式

发布时间:2020-08-16 23:13:52 ,浏览量:3

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript"> function Person()//父类 { this.name=null; this.age=0; this.say=function() { console.log(this.name, this.age); } } function Student() { this.score=0; this.study=function() { console.log("day day up"); } } Student.prototype=new Person();//既然总结没有,就去原型里面找,把Person的实例对象赋值给student的原型对象,实例对象有的东西 Student.prototype.constructor=Student;//为了不破坏关系,这样(构造函数) let stu = new Student(); stu.name = "zs"; stu.age = 18; stu.score = 99; stu.say(); stu.study(); </script> </body> </html> 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.0767s