我有一个 javascript 库,到目前为止,它的结构基本上是这样的:
var Ns = (function(){
var that = {};
// add stuff to 'that'
return that;
})();
//use Ns.foo() and Ns.bar()
问题是现在,我希望相同的库可以与node
and一起使用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
这会破坏浏览器的包含。想法?