Created
July 14, 2015 07:02
-
-
Save georgeOsdDev/4eb0fe776babb17a15d9 to your computer and use it in GitHub Desktop.
Promise
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
let success = (value) => { | |
console.log('success', value) | |
} | |
let fail = (value) => { | |
console.log('fail', value) | |
} | |
let action = (name) => { | |
return new Promise((resolve, reject) => { | |
let now = Date.now(); | |
if (now % 2 === 0) { | |
resolve(`${name} now is even: ${now}`); | |
} else { | |
reject(`${name} now is odd: ${now}`); | |
} | |
}); | |
}; | |
window.addEventListener('click', () => { | |
let p = action("p").then(success, fail); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment