xinonny 2020-11-24 15:29 采纳率: 0%
浏览 142

js中return一个function后这个function中的this指向问题

var length=10

function fn(){
     console.log(this)
    return this.length+1
}

var obj={
    length:5,
    test1:function(){
        return fn();
    }
}
console.log(obj.test1())

这个fn的指向为什么还是window

  • 写回答

1条回答 默认 最新

  • qq_25376897 2020-11-24 15:55
    关注

    test1里面是返回fn(),所以执行console.log(obj.test1())相当于执行console.log(fn())

    评论

报告相同问题?