gpt4 book ai didi

javascript - 当我声明 this = self 时,怎么会有 this != self?

转载 作者:行者123 更新时间:2023-11-29 10:46:39 25 4
gpt4 key购买 nike

我正在尝试为此添加声明一个变量,以便我可以在 http-request-callback 中使用它:

虽然它不起作用,self 变成了窗口对象,而不是“this”。

mycompany.getData(mycompany.save.bind(mycompany))

company.prototype.getData = function(callback){
console.log(this)//outputs the object company
self = this;
console.log(this)//outputs the object company
console.log(self)//outputs the window object
GM_xmlhttpRequest({
...
callback
})
}

最佳答案

self 全局变量指的是 window.self尝试更改代码:

var self = this;

关于javascript - 当我声明 this = self 时,怎么会有 this != self?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18208802/

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