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