Skip to content

Instantly share code, notes, and snippets.

@wellflat
Created November 27, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wellflat/00eee565a8225b731c7289edb17b7cdd to your computer and use it in GitHub Desktop.
Save wellflat/00eee565a8225b731c7289edb17b7cdd to your computer and use it in GitHub Desktop.
promise image loader
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