Skip to content

Instantly share code, notes, and snippets.

@mohayonao
Created April 17, 2013 00:36
Show Gist options
  • Save mohayonao/5400842 to your computer and use it in GitHub Desktop.
Save mohayonao/5400842 to your computer and use it in GitHub Desktop.
画像を一回だけ読み込むやつ
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