In this line:
img.onLoad = this.onLoad(img);
you are incorrectly calling this.onLoad
immediately, rather than passing that function as the load handler. Your code thus completes without ever waiting for the images to be actually loaded.
You also have the case wrong - the handler property should be called img.onload
rather than img.onLoad
.
Note that the .onload
event handler will be called with the image as its this
context variable rather than having it passed as a parameter, so you would use this
(representing the image, not your class) inside that event handler.
The alternative would be to write:
var self = this;
img.onload = function() {
self.onLoad(this);
}