gpt4 book ai didi

javascript - jQuery - 获取对此的引用

转载 作者:行者123 更新时间:2023-11-30 08:15:54 24 4
gpt4 key购买 nike

function Request(params)
{
// Stuff stuff stuff

// And then

$.ajax(
{
type: 'GET',
url: 'someurl',
success: this.done
});
}

Request.prototype.done = function()
{
// "this" in this context will not refer to the Request instance.
// How to reach it?
}

最佳答案

您可以先捕获“this”:

function Request(params)
{
// Stuff stuff stuff

// And then

var $this = this;

$.ajax(
{
type: 'GET',
url: 'someurl',
success: function() { $this.done(); }
});
}

关于javascript - jQuery - 获取对此的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4132403/

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