【发布时间】:2013-05-02 08:20:18
【问题描述】:
我有一个 javascript 库,基本上到目前为止它的结构是这样的:
var Ns = (function(){
var that = {};
// add stuff to 'that'
return that;
})();
//use Ns.foo() and Ns.bar()
问题是现在,我希望 node 和 npm 可以使用相同的库。到目前为止,这是我能想到的:
this.Ns = (function(){ //same as previous snippet })()
//use Ns.foo() and Ns.bar()
问题是,虽然这在浏览器中有效,但在节点中我需要这样做:
var Ns = require('ns').Ns
问题:我希望能够做到var Ns = require('ns'),但为了做到这一点,我必须导出this.foo 和this.bar,这将破坏浏览器的包含。想法?
【问题讨论】: