gpt4 book ai didi

javascript - 如何正确引用 "this"?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:08:37 25 4
gpt4 key购买 nike

<分区>

假设我有以下内容:

var object = {
myfunc: function() {
$.ajax({
url: url,
format: format,
success: function() {

console.log(this) // This refers to the ajax call and not "object"

$.ajax({
url: url,
format: format,
success: function() {
console.log(this) // this refers to nested ajax call and not "object"
}
});


}
});
}
}

如何让“this”引用“object”而不是 ajax 调用?

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