Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Created July 14, 2015 07:02
Show Gist options
  • Save georgeOsdDev/4eb0fe776babb17a15d9 to your computer and use it in GitHub Desktop.
Save georgeOsdDev/4eb0fe776babb17a15d9 to your computer and use it in GitHub Desktop.
Promise
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