标签:blog http com 2014 cti name
function Person(name, profession) {
this.name = name;
this.profession = profession;
this.speak = function () {
document.writeln("我叫"+name+",我是一位"+profession);
}
}
function Student(name,profession) {
Person.call(this,name,profession);
};
function Teacher(name, profession)
{
Person.apply(this, arguments);
}
var student = new Student("张三", "学生");
var teacher = new Teacher("李四", "老师");
student.speak();
teacher.speak();
结果如下
从结果中我们可以看到,apply和call可以实现继承,但call的用法要比apply灵活
js apply 和call的区别,布布扣,bubuko.com
标签:blog http com 2014 cti name
原文地址:http://www.cnblogs.com/bygrace/p/3794880.html