Javascript 延迟所有ajax请求
未捕获类型错误:非法调用 我在尝试延迟应用程序中的所有ajax请求时出现此错误Javascript 延迟所有ajax请求,javascript,Javascript,未捕获类型错误:非法调用 我在尝试延迟应用程序中的所有ajax请求时出现此错误 (function(send) { XMLHttpRequest.prototype.send = function(data) { setTimeout( function () { send.call(this, data); //Error here },3000); }; })(XMLHttpRequest.prototype.send); 你能给我一些提示吗?提前谢谢。
(function(send) {
XMLHttpRequest.prototype.send = function(data) {
setTimeout( function () {
send.call(this, data); //Error here
},3000);
};
})(XMLHttpRequest.prototype.send);
你能给我一些提示吗?提前谢谢。您似乎正在调用
。调用
传递当前作用域,该作用域将是窗口
(function(send) {
XMLHttpRequest.prototype.send = function(data) {
var self = this;
setTimeout( function () {
send.call(self, data); //Updated `this` context
},3000);
};
})(XMLHttpRequest.prototype.send);
我想,在这里,
this
将引用setTimeout函数如何更改它?可能重复的@fluis将其保存到一个变量中,如:var\u this=this
调用setTimeout
可能重复的“which will be setTimeout function”No->this==window