基本不同 1.写法不同,箭头函数使用箭头定义,普通函数中没有
var x='window x'
function fn1(){
console.log(this.x)
}
var fn2=()=>{
console.log(this.x)
}
var obj={
x:"obj x"
}
fn1.call(obj); // obj x
fn1.apply(obj); // obj x
fn2.call(obj); // window x
fn2.apply(obj); // window x
4.箭头函数不可以做构造函数,不能使用new 关键字,因为new关键字是调用函数对象的constructor属性,箭头函数中没有该属性,所以不能new
function fn1(){
console.log('a')
}
var fn2=()=>{
console.log('b')
}
console.dir(fn1)
console.dir(fn2)
new fn1()
new fn2()
输出如下
image.png
5.箭头函数不绑定arguments,取而代之用rest参数…解决 6.箭头函数不可做Generator函数
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有