不适用箭头函数的场景
1、作为构造函数
const Person = () => {};
new Person(); //报错
因为箭头函数没有this。构造函数最重要的就是this
2、需要 this 指向调用对象的时候
document.onclick = function () {
console.log(this); //document
};
document.addEventListener(
'click',
() => {
console.log(this); //window
},
false
);
3、需要使用 arguments 的时候
function add() {
console.log(arguments);
}
add(1, 2,3,4,5);
const add = () => console.log(arguments); //报
因为箭头函数中没有 arguments