Created
March 9, 2019 20:44
-
-
Save 0632347878/63472e5f5f242784a913311cf924aed6 to your computer and use it in GitHub Desktop.
This file contains 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
/_ 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