// 继承的目的是借助已经有的对象去创建新的对象
// 构造函数
// Super
// Sub
function Super(info){
var info = (info)?info:{name:'Super'};
this.name = info.name;
this.hello = function(){
}
}
function Sub(info){
// 构造继承 = 复制
Super.call(this,info);
this.age = info.age;
this.hello = function(){
console.log('hello sub');
}
}
(function(){
var Obj = function(){};
Obj.prototype = Super.prototype;
Sub.prototype = new Obj();
})();
// test code
// 传参
// 没有原型,复用无从谈起
// 目的 使它既属于大类,也属于小类
var info = {
name:'sub',
age:'21'
};
var sub = new Sub(info);
console.log(sub.name);
console.log(sub.age);
sub.hello();
console.log(sub instanceof Super); // true
console.log(sub instanceof Sub); // true