4
我在使用Browserify構建我的包。傳遞參數時無法設置module.exports
我有以下service.js
:
(function (exports, require) {
// ...
var Service = function (name, region) {
this.name = name;
this.region = region;
// ...
}
exports = Service;
})(module.exports, require);
每當我試着require('./service')
其他模塊上,我得到一個空的對象,如果對象exports
從未設置過。
如果我使用module.exports
無參數封裝,一切工作正常:
(function (require) {
// ...
var Service = function (name, region) {
this.name = name;
this.region = region;
// ...
}
module.exports = Service;
})(require);
爲什麼會出現這種情況,這是爲什麼需要?
爲什麼不簡單地返回'Service'並且從iife的結果中分配'exports'? –