ExtJs 4.1再次回调范围

Shl*_*omo 1 scope extjs callback extjs4.1

this在调用我的回调函数时如何保持?

init: function() {

 console.log( this ); // constructor, YES!

 this.readConfig();
},

readConfig: function() {

 console.log( this ); // constructor, YES!

 this.httpApi.request({
    module   : 'monitor',
    func     : 'getConfig',
    success  : this.readConfigCallback,
    scope    : this
 });
},

readConfigCallback: function(oResponse) {

 console.log( this ); // Window, NO!

 var oView = this.getView(); // error...
Run Code Online (Sandbox Code Playgroud)

}

rai*_*7ow 5

使用 ...

success: Ext.bind(this.readConfigCallback, this)
Run Code Online (Sandbox Code Playgroud)

...而是专门将对象的上下文绑定到回调函数.否则,此函数将在全局上下文中调用,其this功能将参考window.