Last active
November 23, 2015 22:27
-
-
Save ceme/f36503e5950f5ed28a5a to your computer and use it in GitHub Desktop.
Simple Implementation of the Promises API in JS
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
var myPromise = function(arg) { | |
return new Promise(function(resolve, reject) { | |
if (arg === true) { | |
resolve('it\'s all good'); | |
} else { | |
reject('no good, buddy'); | |
} | |
}); | |
} | |
var setting = confirm("Press 'OK' to succeed or 'Cancel' to fail"); | |
myPromise(setting).then(function(res){ | |
alert(res); | |
}).catch(function(reason) { | |
alert(reason); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment