I have a problem with passing events from one object to another in Javascript. I tried to use PubSub to do that. Let me give an example:
function A() {
function _publish(){
PubSub.publish("test");
}
function _doSth() {
console.log("Done!");
}
return {
publish: _publish,
doSth: _doSth
};
}
function B() {
var objA = new A();
PubSub.subscribe("test", function(){
objA.doSth();
});
}
That code example is similar to object structure in my application. Instance of B object is public, but instance of object A is private inside B object.
The problem is, that when event "test" is published, it is handled by the pubsub, but because objA is not global, I see in console that doSth function is undefined.
Anyone have an idea how to solve that?