首页 > 编程语言 > 详细

07.30《JavaScript》——模拟继承

时间:2018-07-31 01:19:27      阅读:166      评论:0      收藏:0      [点我收藏+]

模拟继承的三种方式:

1.call()

function Person(name, age) {
                this.name = name;
                this.age = age;
                this.eat = function(name) {
                    alert(this.name +  "正在吃饭");
                }
            }

            function Student(sno, name, age) {
                Person.call(this, name, age);
                this.sno = sno;
                this.study = function() {
                    alert("学号为"+this.sno+"的学生,姓名叫做"+this.name+",正在努力学习,年龄为"+this.age);
                }
            }
            
        
            var stu = new Student(1,‘wang‘,23);
            
            stu.eat();
            stu.study();

 

2.apply()

3.原型链继承prototype

07.30《JavaScript》——模拟继承

原文:https://www.cnblogs.com/justlive-tears/p/9393605.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!