I'm abstracting away the code to focus on the core question. I have a main.js file, which requires a second file, optionsmod.js.
I'd like to be able to send a message from optionsmod.js to main.js, so that main.js can then go on to do other things. I don't know how to do this...
Here is an example that does't work.
main.js:
var optionsmod = require("optionsmod.js");
var self = require("sdk/self");
optionsmod.init();
self.port.on("message",function(){
console.log("message received");
});
optionsmod.js:
var self = require("sdk/self");
function init(){
console.log("here in init");
//FOR THIS EXAMPLE, I'VE MADE THE CALL HERE. BUT WONT BE NORMALLY
sendMessage();
}
function sendMessage(){
self.port.emit("message");
console.log("message sent");
}
exports.init = init;
The code I've added doesn't work, but is there a way to do something similar?