The exampleCode is:
// 4. execute tower.init latter read from bellow (1)
tower={
init:function(){ console.log('horee im here now, finaly after a day code');}
}
// 3. app object
app ={
publish:function(what,data){
data.nextModule.init();
}
}
// 2. then call this funct
var fires = function(){
return app.publish('subscriber',{ nextModule : 'tower'});
}
// 1. execute this first
fires();
Explanation Problem
- When i fire
fires()1. - The 2. isfine
app.publish('text',{nextModule:'tower'); - Bypassed to 3.
app.publish(text,data)
My problem is
I want to convert data.nextmodule --> into an Object or Function
then call the tower module.init()
data.nextModule.init() cannot executed because nextModule is String
how to make this code run like this
data.'tower'.init();
I have reading this reference
Answer by Houshalter converting an object to a string !not an String into an Object
Can node js to that?
Can we covert to object as easy as JSON.stringify(data) ?
UPDATE ERROR on terminal
throw err;
^
TypeError: Object tower has no method `init`