Created
April 17, 2013 00:36
-
-
Save mohayonao/5400842 to your computer and use it in GitHub Desktop.
画像を一回だけ読み込むやつ
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
class ImageLoader | |
map = {} | |
constructor: (@src)-> | |
if not map[@src] | |
@dfd = new $.Deferred | |
map[@src] = @ | |
return map[@src] | |
load: -> | |
img = new Image | |
img.src = @src | |
img.onload = => | |
@dfd.resolve img | |
@load = => | |
do @dfd.promise | |
do @load |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment