How can I keep this when calling my callback function?
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...
}
Use …
… instead to bind the object’s context to the callback function specifically. Otherwise this function will be called in the global context, and its
thisfunction will refer towindow.