1

I know that doing that is bad, but still.

I have a module with utilities I often use. Inside it, if I declare, for example,

JSON.foo = function(){return "Hi!";};

then the JSON.foo method will be available, but only inside the module.


How can I make it available from outside the module, where I require it?

i.e.

var utils = require("utils");
console.log(JSON.foo()); // "Hi!"
4

1 回答 1

1

实用程序.js

JSON.foo = function(){return "Hi!";};
exports.JSON = JSON

使用Utils.js

var utils = require("./utils");
console.log(JSON.foo()); // "Hi!"
于 2013-09-25T13:28:59.737 回答