[英]module.exports in closures
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
函數。
您可以使用:
測試.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");
主文件
require('./test.js').yahoo(); // Hello World
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.