Last active
January 24, 2017 01:36
-
-
Save solominh/43fdc08452df320effca1a95b1e79908 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
var test = () => { | |
new Promise((resolve, reject) => { | |
resolve(undefined); // Will call then | |
}).then(() => { | |
console.log("Then"); | |
}).catch(() => { | |
console.log("Catch"); | |
}) | |
} | |
var test1 = () => { | |
new Promise((resolve, reject) => { | |
resolve(somethingNotDeclareYet); // Exception inside resolve => will call catch | |
}).then(() => { | |
console.log("Then"); | |
}).catch(() => { | |
console.log("Catch"); | |
}) | |
} | |
var test2 = () => { | |
new Promise((resolve, reject) => { | |
resolve(Promise.reject()); // Will call catch | |
}).then(() => { | |
console.log("Then"); | |
}).catch(() => { | |
console.log("Catch"); | |
}) | |
} | |
var test3 = () => { | |
var doSomething = () => { | |
throw new Error('Error') | |
} | |
new Promise((resolve, reject) => { | |
resolve(doSomething()); // Will call Catch | |
}).then(() => { | |
console.log("Then"); | |
}).catch(() => { | |
console.log("Catch"); | |
}) | |
} | |
var test4 = () => { | |
// All 3 promises will call catch | |
var promise1 = Promise.resolve(Promise.reject()) | |
.catch((err) => { | |
console.log(err); //undefined | |
}); | |
var promise2 = Promise.resolve().then(function () { | |
return Promise.reject(); | |
}).catch((err) => { | |
console.log(err); //undefined | |
}); | |
var promise3 = Promise.reject().catch(function () { | |
return Promise.reject(); | |
}).catch((err) => { | |
console.log(err); //undefined | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment