Category:Windows-only software
Category:Disc copy protectionQ:
how to access 'this' object from inside a promise
is there a way to access 'this' from inside a promise (global this)?
i have an object, that is created after document.load is done, i want to use this object from inside the promise (see example).
but it seems like this is not accessible inside the promise function.
the this object is called 'this'.
UPDATE:
in the following example, the callback does get called but not the global 'this'.
$(window).on('load', function(){
var myConfig = {
myConfigParam: {
myConfigParamParam: 'value'
}
}
// the 'this' object does not exist.
myConfig.start(function(){
this.myConfigParam.myConfigParamParam = 'updated value';
}.bind(this));
});
this.start.bind(this) will get called with the 'this' object that is inherited from the dom load (see this.content below)
this.content = this;
UPDATE:
what i want to do, is have the 'this' object that is inherited from the dom load, available in a promise function.
the problem is, that the following example does not work because of the bound.bind(this) - the this is bound to the object from the dom load, instead of to the current instance of the object.
$(window).on('load', function(){
var myConfig = {
myConfigParam: {
myConfigParamParam: 'value'
}
}
// the 'this' object does not exist.
myConfig.start(function(){
this.myConfigParam.myConfigParamParam = 'updated value';
}.bind(this));
});
the solution to this problem is to bind the.bind(this) to the be359ba680
Related links:
Commentaires