I use a Cordova plugin which has two callback functions:
window.plugins.screensize.get(this.screensize_success, this.screensize_error);
Next, in the success callback, I do:
screensize_success(result)
{
console.log(result); // <--- works fine
console.log("##### height: "+result.height); // <--- works fine
this.get_highest(result); // <--- throws an error
}
get_highest(result)
{
return Math.max(result.height,result.width);
}
I get this error:
Uncaught (in promise): TypeError: Cannot read property 'get_highest' of null
What am I doing wrong?
You're losing the this
context when the callback is called.
Simplest way to remedy this is to bind the callbacks to this
:
window.plugins.screensize.get(this.screensize_success.bind(this), this.screensize_error.bind(this));
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments