探索函数作用域(普通函数与箭头函数的区别)

本文详细探讨了JavaScript中的函数作用域,对比了普通函数与箭头函数的区别,揭示了它们在作用域、this指向等方面的不同,帮助开发者更好地理解和使用这两种函数形式。
摘要由CSDN通过智能技术生成
// 探索作用域this,箭头函数域普通函数的区别
// 箭头函数的定义是保证函数里的this是是定义域的this,
// 如果调用他的对象没有该函数,依旧会报undefined is not a Function

function scopeOfFuns(){
    console.log("out fun:",this);
    function scopeOfFunIn(){
        console.log("in funs:",this)
    }
    scopeOfFunIn();
}

const scopeOfArrowFuns = () => {
    console.log("arrow fun out:",this);
    const scopeOfArrowFunsIn = () => {
        console.log("arrow fun in",this);
    }
    scopeOfArrowFunsIn();
}

const scopeOfArrowFuns1 = () => {
    console.log("arrow fun out:",this);
    function scopeOfArrowFunsIn(){
        console.log("arrow fun in",this);
    }
    scopeOfArrowFunsIn();
}

function scopeOfFuns1(){
    console.log("out fun:",this);
    const scopeOfFunIn = () => {
        console.log("in funs:",this)
    }
    scopeOfFunIn();
}

function funTest() {
    const scopeOfFunIn = () => {
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值