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}
http://jsfiddle.net/KbBny/1/内部构造函数原型设置
如何添加sayBar
到b
原型构造函数里面?
b.prototype = new a();
是否覆盖原型,或合并b
的a
的?
原型的整体思路是,你把它定义* *外的构造,而不是内部。 –
阅读此:http://stackoverflow.com/a/8096017/783743 –