Last active
January 7, 2018 04:55
-
-
Save bhuizi/e41ca12cb5cf19a56c278ec7b716dc70 to your computer and use it in GitHub Desktop.
promise example
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
const other = new Promise((resolve, reject) => { | |
let values = [1,2, 3,4, 5]; | |
let sum = values.reduce((acc, next) => { | |
return acc + next; | |
}, 0) | |
resolve(sum); | |
reject('something went wrong'); | |
}); | |
let fullName = (first, last) => { | |
return new Promise((resolve, reject) => { | |
let fullName = `fullname is ${first} ${last}`; | |
resolve(fullName); | |
reject('ooops'); | |
}) | |
} | |
let joey_smith = fullName('joey', 'smith'); | |
joey_smith.then(data => console.log(data)).catch(err => err); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment