https://github.com/azu/promises-book
http://it-ebooks24.com/ebook/mastering-javascript-promises
传值,调用,错误处理,抛出,都有了哈。
function taskA(value) { console.log("Task A"); return value * 2; //throw new Error("throw Error @ Task A"); } function taskB(value) { console.log("Task B"); return value + 1; } function onRejected(error) { console.log("Catch Error: A or B", error); } function finalTask(value) { console.log("Final Task " + value); } var promise = Promise.resolve(10); promise .then(taskA) .then(taskB) .catch(onRejected) .then(finalTask);
时间: 2024-09-26 12:33:55