Below is my problem code:
var counter = new Counter();
counter.Load("20141211");
--
Counter = function () {
this.Counters = new Array();
this.Load = function (date) {
$.getJSON("http://url", { "Date": date }, function (Count) {
if (!Count.Error) {
this.Counters[this.Counters.length] = Count;
}
});
}
}
The line this.Counters[this.Counters.length] = Count;
is where this.Counters
is undefined and I don't understand why as it is defined above.
I would think it got defined when I call new Counter()
, so it can be used later when I call counter.Load()
. But it is simply undefined.
If I where to create this as a linear code it would work:
var Counters = new Array();
Counters[Counters.length] = Count;