en.javascript.info/8-async/03-promise-chaining/head.html
Ilya Kantor c96881755e minor
2017-04-07 00:20:56 +03:00

10 lines
270 B
HTML

<script>
function loadImage(src) {
return new Promise((resolve, reject) => {
let img = document.createElement('img');
img.src = src;
img.onload = () => resolve(img);
img.onerror = () => reject(new Error("Image load failed: " + src));
});
}
</script>