/** * Created by Administrator on 2014/9/4. */ var util = require('util'); function Base() { this.name = '李斌'; this.base = '1992'; this.sayHello = function() { console.error('Hello' + this.name); } } Base.prototype.showName = function() { console.log(this.name); } function Sub() { this.name = '小样'; this.base = '1993'; } util.inherits( Sub , Base ); var objBase = new Base(); var objSub = new Sub(); objBase.showName(); objBase.sayHello(); console.error(objBase); objSub.showName();/* showName为Baes的原型函数,允许被子类继承并调用 */ //objSub.sayHello();/* sayHello为Base内部构造的函数不允许被继承调用 */ console.log(objSub);