I'm attempting to make a class in javascript. I create it with the JSON type object thing.
Doing this:
Foo = {
PubId: '',
Init:function( oCallback )
{
this.sendCommand( 'INIT', {}, oCallback );
},
sendCommand : function( sCommand, aParams, oCallback )
{
setTimeout( oCallback, 1000, '{"response":"INIT","time":1287982024,"pubid":"4cc50bc47c7b3"}' );
return true;
},
onData : function( sData )
{
var aRes = JSON.parse( sData );
this.PubId = aRes.pubid;
alert( this.PubId );
return this.PubId;
},
umtest:function(){ alert( this.PubId ); }
}
I then also do this after including the script:
Foo.Init( Foo.onData );
The problem is that the this.PubId is updated inside the onData method, but outside of it, the pubid is empty.
I am pretty new at javascript classes, so I'm not sure what needs to be done so I was hoping someone could help meh out. :)
Thanks for your time!