Skip to content

Instantly share code, notes, and snippets.

@gusmantap
Created October 7, 2019 03:41
Show Gist options
  • Save gusmantap/b69553a2bc5be8d47f3ee43875f4bf2d to your computer and use it in GitHub Desktop.
Save gusmantap/b69553a2bc5be8d47f3ee43875f4bf2d to your computer and use it in GitHub Desktop.
// 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