I have a RequireJS module I am writing, that I am using to wrap the ASYNC methods used by LG's webOS SCAP library (this is a Cordova based library that allows easy interaction with webOS, on the "Signage" screens).
The SCAP methods rely on success and failure callbacks.
In one of my success callbacks, I need to call another method in the same module.
I tried using "var self = this" and then calling "self.methodName" but it is always undefined. If I debug, the "self" reference seems to be correctly populated, showing all the "window" data. But the method is undefined.
I have been able to call methods within the same module, in other modules, and it works. but this is the first time I am trying to call it from within a nested function.
Code:
define(["settings"], function(settings) {
return {
updateProgress: function() {
var self = this;
// this is called when the statFile function succesfully finds the file and can read its properties
var successCb = function(cbObject) {
self.getDownloadSpeed(); // "self" is defined, getDownloadSpeed isn't.
};
var failureCb = function(cbObject) {
// stuff here
};
var options = {
// stuff here
};
settings.storage.statFile(successCb, failureCb, options); // SCAP method used to get file info (size, date modified etc)
},
getDownloadSpeed: function() {
// stuff here
}
};
});