Question about scope...
Filed Under mercialleasing.com |
Never quite delved into Ext's little scope variable, but I've encountered a situation where I believe it may be useful/necessary. Please forgive the semantics of what follows, just meant to be a cursory example:
MyDesktop.AModule = Ext.extend( Ext.app.Module, {
fictitiousVar: 'abc',
init: function(){
this.launcher = {
// ...yadayada
handler: this.createWindow
scope: this
}
},
createWindow: function(){
var c = new Ext.data.Connection();
c.timeout = 5000;
c.request({
url: admrpcURL,
method: 'post',
params: { action: 'test' },
headers: { 'Accept' : 'application/json' },
callback: function( options, success, transport ){
alert( this.fictitiousVar ); // QUESTION HERE
}
});
}
);
The callback for the request in 'createWindow' attempts to access the 'fictitiousVar' member of the instantiated MyDesktop.AModule object. Scope is lost however, this. has no salience when the callback is executed...
What's the Extish way of solving this? Is there a little scope value I can tuck somewhere? Or do I need to pass a reference to the object to the callback somehow? Is a better solution to assign a callback that is a member function?
Thanks as always!
Alex
Cheers.
A
#If you have any other info about this subject , Please add it free.# |