Skip to content

Instantly share code, notes, and snippets.

@ceme
Last active November 23, 2015 22:27
Show Gist options
  • Save ceme/f36503e5950f5ed28a5a to your computer and use it in GitHub Desktop.
Save ceme/f36503e5950f5ed28a5a to your computer and use it in GitHub Desktop.
Simple Implementation of the Promises API in JS
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