scope - Javascript Object Function Scoping -
let's have class:
var asdf = new class({ myfunction: function () { //some stuff here }, anotherfunction: function() { globalobject.dosomethingandusecallback( function() { // callback //how call myfunction() here? can't seem work? } ); } }); i seem have scoping problems in trying call myfunction within definition of callback function. missing here? thought should have access myfunction in context?
thanks!
copy this keyword variable outside of callback function, , use variable inside callback:
anotherfunction: function() { var self = this; globalobject.dosomethingandusecallback( function() { // callback self.myfunction(); } ); }
Comments
Post a Comment