The following code is from a simple page which displays a paginated table.
var exviewmodel = function() {
var self = this;
self.getList = function(pagenum) {
$.getJSON("/api/v1/getList", { page: pagenum }, function(data) {
self.paginator.count(data.count);
});
};
self.paginator = new Paginator(self.getList);
};
I checked and verified that the code works and the count gets updated correctly in the paginator on ajax success.
I find this strange as the paginator object is being initialized only after the ajax callback has been defined.
What exactly does the JS interpreter do when it sees a function definition like getList which refers to properties which have not yet been initialized inside a async callback?