varutil=require('util');functionBase(){this.name='base';this.base=1991;this.sayHello=function(){console.log('Hello'+this.name);};}Base.prototype.showName=function(){console.log(this.name);};functionSub(){this.name='sub';}util.inherits(Sub,Base);varobjSub=newSub();console.log(objSub);很明显会打印{name:'sub'}Sub仅仅继承了Base在原型中定义的函数,而构造函数内部创造的base属性和sayHello函数都没有被Sub继承。那么如何继承构造函数内部创造的base属性和sayHello函数求解答
相关分类