javascript 为什么我收到“无法从释放的脚本执行代码”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15830442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:15:29  来源:igfitidea点击:

Why do I get "Can't execute code from a freed script"

javascript

提问by Andreas Niedermair

First of all: Yes, I've read this answer... And, Yes, there's no meta after script (as I do not have any meta on my page), and, No, there's no timeout or ajax-request

首先:是的,我已经阅读了这个答案......而且,是的,脚本之后没有元(因为我的页面上没有任何元),并且,不,没有超时或ajax请求

I have following helper-method (Yes, I could have made a prototype-method ...):

我有以下辅助方法(是的,我可以制作一个原型方法......):

function removeElementFromArray(array, compareMethod) {
    if (!array) {
        return;
    }
    if (!$.isFunction(compareMethod)) {
        return;
    }
    var index = getIndexOfElement(array, compareMethod);
    if (index < 0) {
        return;
    }
    array.splice(index, 1);
}
function getIndexOfElement(array, compareMethod) {
    if (!array) {
        return -1;
    }
    if (!$.isFunction(compareMethod)) {
        return -1;
    }
    for (var i = 0; i < array.length; i++) {
        var element = array[i];
        if (compareMethod(element)) {
            return i;
        }
    }
    return -1;
}

I am calling this with:

我打电话给这个:

$foo.on('click', function () {
    removeElementFromArray(window.myArray, function (element) {
        return // some condition
    });
});

I am getting the exception "SCRIPT5011: Can't execute code from a freed script" (only in IE render-mode < 10) in following line:

我在以下行中收到异常“SCRIPT5011:无法从释放的脚本中执行代码”(仅在 IE 渲染模式 < 10 中):

array.splice(index, 1);

But not on the first call, but on any subsequent ones (for the same array) ...

但不是在第一次调用时,而是在任何后续调用中(对于同一个数组)......

But I can't think of a single reason why this exception occurs, as I am accessing the array in other lines as well in the callstack (as you can see, eg getIndexOfElement, where I iterate over the array).

但我想不出发生此异常的单一原因,因为我正在访问其他行中的数组以及调用堆栈中的数组(如您所见,例如 getIndexOfElement,我在其中遍历数组)。

Can anybody help me out?

有人可以帮我吗?

采纳答案by Tommi

This questioncontains a good answers about iframes relationship. (Added as answer by OP suggestion).

这个问题包含一个关于 iframes 关系的很好的答案。(根据 OP 建议添加为答案)。