gpt4 book ai didi

javascript - 类中的箭头函数方法

转载 作者:行者123 更新时间:2023-11-30 19:29:02 25 4
gpt4 key购买 nike

<分区>

据我了解,箭头函数没有 this 关键字,它采用父级 this 值。那么这是如何工作的呢? func 属性中 this 的值不是指向 window 对象吗?它如何指向类并返回名称?

class app {
constructor(name){
this.name=name
}

func() => {return this.name}
}

let a = new app('william')
a.func()
// william

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com