function inherit(Child, Parent) {
var F = function(){};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.prototype.constructor = Child;
Child.uber = Parent.prototype;//uber是一个德语词,意思是"向上"、"上一层",可以使用这个属性直接调用父级对象
}
这种继承方法中的属性和方法只有在prototype中才能被继承
var log = console.log.bind(console);
function O(config) {
this.a = 'a';
}
O.prototype = {
b:'b',
move: function() {
log(this.a);
}
}
var Child = function(){
};
inherit(Child, O);
var child = new Child();
log(child.b)//b
log(child.a)//undefined