console.log("普通函数方式");
var arr1 = [1, 2, 3, 4, 5];
arr1.forEach(function(e) {
console.log(e);
});
console.log("箭头函数方式");
var arr2 = [1, 2, 3, 4, 5];
arr2.forEach((e) => console.log(e));
function taskA() {
console.log("Task A");
// throw new Error("taskA掉坑里了");
}
function taskB() {
console.log("Task B");
throw new Error("taskB掉坑里了");
}
function onRejected(error) {
console.log("onRejected catch Error: A or B", error);
}
function finalTask() {
console.log("Final Task");
}
var promise = Promise.resolve();
promise
.then(taskA) // 和task A/B
.then(taskB)
.catch(onRejected)
.then(finalTask);
console.log('promise finish'); // promise finish 打印顺序
标签:function,console,log,taskA,箭头,taskB,promise,函数
From: https://www.cnblogs.com/simp/p/17027599.html