0
以下代碼總是打印它應該打印的地方任何關於我在做什麼錯誤的建議?或者這是預期的?Nodejs util.inherits產生意想不到的結果
var EventEmitter = require("events").EventEmitter,
util=require('util');
var Car=function(){
var self=this;
EventEmitter.call(this);
var make=1;
Car.prototype.getMake = function() {
return make;
};
Car.prototype.setMake = function(val) {
make=val;
return make;
};
}
util.inherits(Car, EventEmitter);
function Bmw(){
Car.call(this);
}
function Merc(){
Car.call(this);
}
util.inherits(Bmw, Car);
util.inherits(Merc, Car);
var car1=new Bmw();
car1.setMake(2);
var car2=new Merc();
car2.setMake(3);
console.log(car1.getMake(),car2.getMake());