Created
October 7, 2019 03:41
-
-
Save gusmantap/b69553a2bc5be8d47f3ee43875f4bf2d to your computer and use it in GitHub Desktop.
This file contains 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
// Functionnya | |
function getImage(url) { | |
return new Promise(function(resolve, reject) { | |
var img = new Image(); | |
img.onload = function() { | |
resolve(url); | |
}; | |
img.onerror = function() { | |
reject(url); | |
}; | |
img.src = url; | |
}); | |
} | |
// Cara pakai functionnya | |
getImage("imgUrl") | |
.then(function(successUrl) { | |
//do stufff | |
}) | |
.catch(function(errorUrl) { | |
//do stuff | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment