I'm trying to call a function as a callback from another function within the same file.
Code below, shows no errors, but does nothing - is there a different/better way to do this?
I'm calling first function from require config file (require-main.js) and that works fine
define(['require-main'], function() {
require(['getJSON'], function(getJSON) {
getJSON.stations();
});
});
getJSON.js
define(['jquery', 'domChange', 'setUp'], function($, domChange, setUp) {
var self = this;
return {
stations: function() {
$.get('/js/ajax/stations.json', function(sol) { /* local JSON */
tmv.stations = sol;
console.log(sol); /* this is fine */
self.lines; /* <-- call next function */
});
},
lines: function() {
console.log('foo'); /* NOT called */
$.get('/js/ajax/lines.json', function(lines) { /* local JSON */
/* do something */
});
}
}
});
I've seen this question but I can't work this way as the order is not predetermined
Update: as above, tried caching this into var but still no joy
this.linesthis is the reference of the function, you are not actually calling it