gpt4 book ai didi

javascript - 如何将上下文传递给 forEach() 匿名函数

转载 作者:可可西里 更新时间:2023-11-01 01:46:47 25 4
gpt4 key购买 nike

<分区>

this 上下文传递给匿名 forEach 函数的现代且正确的方法是什么?

function Chart() {

this.draw = function(data) {
data.forEach(function(value) {
//do something with values
console.log(this); //question: how to get Chart instead of global scope?
)};
});

};

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