Created
January 29, 2012 19:42
-
-
Save anonymous/1700322 to your computer and use it in GitHub Desktop.
sgflt - pastebin.com/drsKKm4n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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