Here is my code snippet:
var tradingInterface = function() {
this.json = '';
this.init = function() {
$.get( '/whatever',{}, function(data) {
this.json = data;
// Rebuilds Everything
this.rebuildAll();
});
};
this.rebuildAll = function() {
//whatever here
};
};
I'm encountering an error in the init function, specifically:
ReferenceError: this.rebuildAll is not defined
this.rebuildAll();
It's interesting that I can access this.json without any scoping issues, but why am I unable to access this.rebuildAll?
I tried referring back to a previous thread on How to access the correct `this` / context inside a callback?, but I haven't been successful in resolving the issue.
Following the suggestions from the thread, I made some changes:
var tradingInterface = function() {
this.json = '';
var self = this;
this.init = function() {
$.get( '/whatever',{}, function(data) {
this.json = data;
// Rebuilds Everything
self.rebuildAll();
});
};
this.rebuildAll = function() {
//whatever here
};
};
The error has disappeared, but now the rebuildAll function doesn't seem to work as expected...
I would appreciate some assistance with this.
Thank you,