gpt4 book ai didi

javascript - 猴子修补 XMLHttpRequest.prototype.open 和 "touching"参数

转载 作者:可可西里 更新时间:2023-11-01 02:12:51 24 4
gpt4 key购买 nike

我正在尝试为在 IE8 兼容模式下运行的 Intranet 站点打补丁 XMLHttpRequest.prototype.open 但它一直抛出 SCRIPT438: Object doesn't support this property or method。奇怪的是...如果我先“触摸”arguments,即取消注释 bar,它工作得很好!有谁知道为什么,如果触摸它确实可以在 100% 的情况下解决问题?

var foo = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function() {
//var bar = arguments;
foo.apply(this, arguments);
console.log("OK");
}

这是 IE9 在 IE8 模式下的 modern.ie VM 屏幕截图,使用 Google Image 搜索尝试打开滚动时的猴子修补请求。

enter image description here

编辑:

console.log(foo);
//console.log(foo.apply);
console.log(typeof foo);
console.log(foo instanceof Function);

返回

LOG: 
function open() {
[native code]
}

LOG: object
LOG: false

console.log(foo.apply) 抛出 “对象不支持此属性或方法”

有趣的是,我无法在实际的 IE8 VM 中以我尝试过的任何模式复制它,只能在以 IE8 标准模式运行的 IE9 中复制它。

最佳答案

我最近看到一个 XMLHttpRequest.prototype.open 被重写的例子,与你的方法略有不同;

(function(open) {
XMLHttpRequest.prototype.open = function() {
// your special sauce

open.apply(this, arguments);
};
})(XMLHttpRequest.prototype.open);

你能检查一下这样做是否有任何不同吗?

关于javascript - 猴子修补 XMLHttpRequest.prototype.open 和 "touching"参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26243141/

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