var a = function(){
this.sayFoo = function(){
console.log('foo');
};
}
var b = function(){
console.log(this.prototype); //undefined
this.sayBar = function(){
console.log('bar');
};
}
b.prototype = new a();
var bInst = new b();
bInst.sayFoo();
bInst.sayBar();
console.log(b.prototype); //a {sayFoo: function}
如何在函数构造函数中添加sayBar
原型b
?
b.prototype = new a();
会覆盖原型,还是将b
's 与a
's合并?