【发布时间】:2013-02-21 23:19:49
【问题描述】:
我正在使用 util.inherits method from node.js 并且似乎无法获得所需的行为。
var util = require("util");
function A() {
this.name = 'old';
}
A.prototype.log = function(){
console.log('my old name is: '+ this.name);
};
function B(){
A.call(this);
this.name = 'new';
}
util.inherits(B, A);
B.prototype.log = function(){
B.super_.prototype.log();
console.log('my new name is: ' + this.name);
}
var b = new B();
b.log();
结果是:
my old name is: undefined
my new name is: new
但是我想要的是:
my old name is: new
my new name is: new
我错过了什么?
【问题讨论】:
标签: node.js inheritance