var object = {}; // Global Object
(function() {
var theArg, google, yahoo;
object.google = function(arg) {
theArg = arg;
alert(theArg);
}
object.yahoo = function() {
alert(theArg);
}
module.exports = yahoo;
})();
// This will set initial value of
google("Hello World");
我可以打电话给这样的module.exports = yahoo
;并在其中调用yahoo
函数。
答案 0 :(得分:1)
您可以使用:
<强> test.js 强>
var object = {}; // Global Object
alert = console.log;
(function() {
var theArg, google, yahoo;
object.google = function(arg) {
theArg = arg;
alert(theArg);
}
object.yahoo = function() {
alert(theArg);
}
module.exports.yahoo = object.yahoo;
})();
// This will set initial value of
object.google("Hello World");
<强> main.js 强>
require('./test.js').yahoo();