Skip to content

Instantly share code, notes, and snippets.

Created January 29, 2012 19:42
Show Gist options
  • Save anonymous/1700322 to your computer and use it in GitHub Desktop.
Save anonymous/1700322 to your computer and use it in GitHub Desktop.
sgflt - pastebin.com/drsKKm4n
What I want: Load a number of images and fire a callback once all are loaded. The image objects of all images need to be available, this is *not* just for caching.
Example use:
var loader = new ImageLoader();
var img1 = loader.addImage('someurl');
var img2 = loader.addImage('anotherurl');
loader.beginLoading(function() {
/* do something with the loaded images img1 and img2, which are Image objects
});
To do this in an OOP-way, I surely need to save the image-urls that are added to the loader using a list. I see only two ways to intialize the list: Inside the ImageLoader constructor or checking in addImage if it has been initialized yet, doing so if need be. The latter approach seems rather wasteful.
However, using the constructor method means that when trying to not use 'new', the Object.create()-way of creating the ImageLoader needs to explicitly call the constructor, which isn't elegant either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment