You don't need to use this
, you need to create a closure.
function timetable(){
// create a closure
var timetables = Array();
//get timetable data for currentUser
$.get('http://someurl.com/api',function(data){
// this references the Array created above
that.timetables = that.timetables.concat($.parseJSON(data));
});
}
It just occurred to me that you may be using timetable
to create objects. As a side note, if that's the case, the convention is to call it Timetable
for clarity. If that's the case, use something like this.
function Timetable () {
// store a reference to the scope
var that = this;
// create an instance property of the Timetable object
this.timetables = [];
$.get('http://someurl.com/api',function(data){
// use our scope reference captured above
// to update the timetables property
that.timetables = that.timetables.concat($.parseJSON(data));
});
}
var t = new Timetable();
// once the get call is complete
console.log(t.timetables);