Question about scope...

Filed Under mercialleasing.com |

  • Hi Guys,

    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


  • you can also use anyFn.createDelegate(this) to enforce scope on an anon function.


  • Looks like a scope: var in the request method solves the problem. Found on http://extjs.com/deploy/dev/docs/?class=Ext.data.Connection

    Cheers.
    A







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Question about scope... , Please add it free.

    Comments