其中的代码示例来自于http://web.jobbole.com/83319/博文
类式继承
在子函数中通过call和apply调用父函数的构造函数
栗子:
var father = function() {
this.age = 52;
this.say = function() {
alert('hello i am '+ this.name ' and i am '+this.age + 'years old');
}
}
var child = function() {
this.name = 'bill';
father.call(this);
}
var man = new child();
man.say();
原型式继承
通过原型链来实现继承,将子函数的prototype赋值为父函数实例化对象,举个栗子:
var father = function() {
}
father.prototype.a = function() {
}
var child = function(){}
//开始继承
child.prototype = new father();
var man = new child();
man.a();