箭头函数不简化Promise的then链式调用逻辑,但能精简回调写法、提升可读性;支持单参数省略括号和return、多步链式处理、隐式继承this、需配合显式catch处理错误。

箭头函数本身不简化 Promise 的 then 链式调用逻辑,但它能显著精简回调函数的写法,让链更干净、更易读。
用单参数箭头函数省略括号和 return
当 then 的回调只接收一个参数且直接返回值时,可省略花括号和 return 关键字:
// 传统写法
promise.then(function(data) {
return processData(data);
});
// 箭头函数简化后
promise.then(data => processData(data));
多步处理时保持链清晰
连续多个 then 中,每个箭头函数专注单一职责,避免嵌套:
// 获取用户 → 解析 JSON → 提取 name → 转大写
fetch('/api/user')
.then(res => res.json())
.then(user => user.name)
.then(name => name.toUpperCase())
.then(upperName => console.log(upperName));
注意 this 和 arguments 的隐式绑定
箭头函数没有自己的 this 和 arguments,适合在 Promise 链中避免上下文丢失,但不适合需要动态 this 的场景(如方法调用):
立即学习“Java免费学习笔记(深入)”;
// ✅ 安全:箭头函数继承外层 this,不会出错
const obj = {
value: 42,
getValue() {
return Promise.resolve(100)
.then(x => x + this.value); // this 指向 obj
}
};
// ❌ 危险:普通函数中 this 可能丢失
.then(function(x) { return x + this.value }) // this 不一定指向 obj
错误处理仍需显式 catch
箭头函数不影响错误传播,catch 依然捕获整条链中的异常:
fetch('/api/data')
.then(res => res.json())
.then(data => data.items.map(item => item.id))
.catch(err => console.error('请求或解析失败:', err));


















