我正在使用直接Web Remoting (DWR) JavaScript库文件,只在Safari(桌面和iPad)中得到一个错误

它说

超过最大调用堆栈大小。

这个错误到底是什么意思,它是否完全停止处理?

Safari浏览器也有任何修复(实际上是在iPad Safari上,它说

JS:执行超时

我认为这是相同的调用堆栈问题)


当前回答

在我的例子中,我基本上忘记了获取输入的值。

错误的

let name=document.getElementById('name');
param={"name":name}

正确的

let name=document.getElementById('name').value;
param={"name":name}

其他回答

这意味着在代码的某个地方,您正在调用一个函数,该函数又调用另一个函数,以此类推,直到达到调用堆栈限制。

这几乎总是因为递归函数的基本情况没有得到满足。

查看堆栈

考虑这段代码…

(function a() {
    a();
})();

下面是几次调用后的堆栈…

正如您所看到的,调用堆栈不断增长,直到达到极限:浏览器硬编码的堆栈大小或内存耗尽。

为了修复它,确保你的递归函数有一个基本情况,能够满足…

(function a(x) {
    // The following condition 
    // is the base case.
    if ( ! x) {
        return;
    }
    a(--x);
})(10);

我使用React-Native 0.61.5以及(npm 6.9.0和节点10.16.1)

当我安装任何新的库在项目我得到了一个

(例如NPM install @react-navigation/native——save)

最大调用堆栈大小超过错误

为此,我尽力了

Sudo NPM缓存清理-force

(注:-以下命令通常需要1 ~ 2分钟 取决于你的NPM缓存大小)

这也会导致最大调用堆栈大小超过错误:

var items = [];
[].push.apply(items, new Array(1000000)); //Bad

我也一样:

items.push(...new Array(1000000)); //Bad

来自Mozilla文档:

But beware: in using apply this way, you run the risk of exceeding the JavaScript engine's argument length limit. The consequences of applying a function with too many arguments (think more than tens of thousands of arguments) vary across engines (JavaScriptCore has hard-coded argument limit of 65536), because the limit (indeed even the nature of any excessively-large-stack behavior) is unspecified. Some engines will throw an exception. More perniciously, others will arbitrarily limit the number of arguments actually passed to the applied function. To illustrate this latter case: if such an engine had a limit of four arguments (actual limits are of course significantly higher), it would be as if the arguments 5, 6, 2, 3 had been passed to apply in the examples above, rather than the full array.

所以尝试:

var items = [];
var newItems = new Array(1000000);
for(var i = 0; i < newItems.length; i++){
  items.push(newItems[i]);
}

我有这个错误,因为我有两个同名的JS函数

如果你因为某些原因需要一个无限的进程/递归运行,你可以在一个单独的线程中使用webworker。 http://www.html5rocks.com/en/tutorials/workers/basics/

如果你想操纵dom元素并重新绘制,请使用动画 http://creativejs.com/resources/requestanimationframe/