0
在节点中,我创建了一个通过websockets连接到模块的模块实例。我用const slackbot = new SlackBot()
这样做。我如何设置,以便我可以在几个不同的模块中引用相同的slackbot
?每次我想在模块中调用slackbot
时,最好的方法就是将模块函数传递给模块函数?这样做的NodeJS:引用多个模块中的相同变量
const slackbot = new SlackBot();
someModule.doThing(data, slackbot)
.then((response) => {
otherModule.doAnotherThing(response, slackbot);
})
.then((response) => {
someModule.wrapUp(response, slackbot);
});
“难道只是为了打发slackbot到模块的功能我想该模块中调用它每次的最佳方式?”是。有办法使它成为一个全球性的,但他们不是很好的风格。 – Ryan