Skip to content

Instantly share code, notes, and snippets.

@0632347878
Created March 9, 2019 20:44
Show Gist options
  • Save 0632347878/63472e5f5f242784a913311cf924aed6 to your computer and use it in GitHub Desktop.
Save 0632347878/63472e5f5f242784a913311cf924aed6 to your computer and use it in GitHub Desktop.
/_ ES6 _/
const isMomHappy = true;
// Промис
const willIGetNewPhone = new Promise(
(resolve, reject) => { // fat arrow
if (isMomHappy) {
const phone = {
brand: 'Samsung',
color: 'black'
};
resolve(phone);
} else {
const reason = new Error('mom is not happy');
reject(reason);
}
}
);
const showOff = function (phone) {
const message = 'Hey friend, I have a new ' +
phone.color + ' ' + phone.brand + ' phone';
return Promise.resolve(message);
};
// Вызываем промис
const askMom = function () {
willIGetNewPhone
.then(showOff)
.then(fulfilled => console.log(fulfilled)) // fat arrow
.catch(error => console.log(error.message)); // fat arrow
};
askMom();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment