Last active
August 2, 2018 21:23
-
-
Save sethdavis512/fed3148c3fc4580db786cc97255e5f9a to your computer and use it in GitHub Desktop.
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
/* ES5, using Bluebird */ | |
var isMomHappy = true; | |
// Promise | |
var willIGetNewPhone = new Promise( | |
function (resolve, reject) { | |
if (isMomHappy) { | |
var phone = { | |
brand: 'Samsung', | |
color: 'black' | |
}; | |
resolve(phone); | |
} else { | |
var reason = new Error('mom is not happy'); | |
reject(reason); | |
} | |
} | |
); | |
// call our promise | |
var askMom = function () { | |
willIGetNewPhone | |
.then(function (fulfilled) { | |
// yay, you got a new phone | |
console.log(fulfilled); | |
}) | |
.catch(function (error) { | |
// ops, mom don't buy it | |
console.log(error.message); | |
}); | |
} | |
askMom(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment