为什么
var EventEmitter = require('events').EventEmitter;
var channel = new EventEmitter();
有效,但是
var EventEmitter = require('events');
var channel = new EventEmitter();
不工作!实际上,我还有另一个完全不同的例子,
var Currency = require('./currency)
var Cu = new Currency();
有效,但是
var Currency = require('./currency).Currency;
var Cu = new Currency();
不起作用。这是我的currency.js:
function Currency(canadianDollar) {
this.canadianDollar = canadianDollar;
}
module.exports = Currency;
Currency.prototype.cal = function(amount) {
return amount * this.canadianDollar;
}