JSFiddle - React, Tailwind, and code Playground
by dougiei
JavaScript
var isMomHappy = false;
var didIgetthephone=function(result, detail) {
if (result ==='OK')
{ console.log("!!",detail)
}
else
{
console.log("damn",detail)
}
};
// 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 () {
console.log("asking...");
willIGetNewPhone
.then(function (fulfilled) {
// yay, you got a new phone
didIgetthephone("OK",fulfilled);
})
.catch(function (error) {
// ops, mom don't buy it
didIgetthephone("NO",error);
});
}
askMom();
console.log("doing something else");