Created
November 27, 2017 13:04
-
-
Save wellflat/00eee565a8225b731c7289edb17b7cdd to your computer and use it in GitHub Desktop.
promise image loader
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
let loadImage = ({ src }) => { | |
return new Promise((resolve, reject) => { | |
let img = new Image(); | |
img.onload = () => { | |
resolve(img); | |
}; | |
img.src = src; | |
}); | |
}; | |
loadImage({ | |
src: 'http://localhost:8000/test.png', | |
}).then((img) => { | |
console.log(`img: ${img}`); | |
document.body.appendChild(img); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment