- 箭头函数是没有arguments的,用了会报错
<script>
const fn1=()=>{
console.log('arguments',arguments);
}
fn1(100,200)
</script>
箭头函数输出arguments报错
- 当箭头函数改为普通函数时,可以正常输出arguments
<script>
// 普通函数
function fn1(){
console.log('arguments',arguments);
}
fn1(100,200)
</script>
- 箭头函数中的call和apply和bind方法无法修改this的指向
const fn2=()=>{
console.log('this',this);
}
fn2.call({x:100})
- 普通函数时this可以被call修改this指向
function fn2(){
console.log('this',this);
}
fn2.call({x:100})
- 在对象里面箭头函数不能被当做对象的方法使用
const obj={
name:'zhu',
getName:()=>{
return this.name
}
}
console.log(obj.getName());