. , this Javascript. Foo.onData setTimeout( oCallback, ...), this not Foo.
Foo this, :
sendCommand: function (sCommand, aParams, oCallback) {
var that = this;
setTimeout(function () {
oCallback.call( that,
'{"response":"INIT","time":1287982024,"pubid":"4cc50bc47c7b3"}' );
}, 1000);
return true;
},
, , onData:
// is `this` really Foo or the global object?
alert(this === Foo); // should be true
alert(this === window); // should be false
this Foo .
, , , , setTimeout, 1000 ms = 1s, , alert(Foo.PubId) Foo ( ).
, Foo.PubId :
setTimeout( function () {
alert(Foo.PubId);
}, 2000);
.