基本上,我正在尝试清理我的代码,我不想要做mc.module1(mc.ticket,function(data){});我只是想让模块容器保存票证,并在调用它们时自动将票证传递给单独的模块函数。
那么,我该怎么做呢。
***main.js
var mc = recuire('modulecontainer.js');
mc.module1(funtion(data){//bla bla do something with data});
***modulecontainer.js
var module1 = require('module1.js');
var module2 = require('module2.js');
var ticket="someChangingAuthenticationCode";
module.exports={
module1:module1(ticket),
module2:module2(ticket)
}
function updateTicket(){
//code that updates the authentication ticket at the required interval
}
***module1.js
module.exports={
a:function(ticket,callback){
//bla bla use authetication ticket to request some data....
callback(data)
}
}
***module2.js
///bla bla very similar to module1 just requesting and proccessing different data