ES6箭头函数和普通函数 有哪些关键差异?
【概念释义】
箭头函数 vs 普通函数 的核心差异在 this 绑定、arguments、是否可 new、prototype 与 yield(生成器) 支持。箭头适合回调与词法 this;普通函数适合对象方法、构造函数、需要动态 this 的场景。
面试必须能结合代码说明 this 指向,而非只背表格。
【基础使用】
javascript
const obj = {
n: 1,
incNormal() {
this.n += 1;
return this.n;
},
incArrow: () => {
登录查看完整 1403 字
回答讨论
暂无讨论,登录后可抢先发言