标签:style UNC cal script 继承 function bsp span nbsp
模拟继承的三种方式:
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
标签:style UNC cal script 继承 function bsp span nbsp
原文地址:https://www.cnblogs.com/justlive-tears/p/9393605.html