admin管理员组文章数量:1287776
In Chrome and Node, the following code throws an error:
function noop() {}
var a = new Array(1e6)
// Array[1000000]
noop.apply(null, a)
// Uncaught RangeError: Maximum call stack size exceeded
I understand why it might be a Bad Idea to pass 1 million arguments to a function, but can anyone explain why the error is Maximum call stack size exceeded
instead of something more relevant?
(In case this seems frivolous, the original case was Math.max.apply(Math, lotsOfNumbers)
, which is a not-unreasonable way of getting the max number from an array.)
In Chrome and Node, the following code throws an error:
function noop() {}
var a = new Array(1e6)
// Array[1000000]
noop.apply(null, a)
// Uncaught RangeError: Maximum call stack size exceeded
I understand why it might be a Bad Idea to pass 1 million arguments to a function, but can anyone explain why the error is Maximum call stack size exceeded
instead of something more relevant?
(In case this seems frivolous, the original case was Math.max.apply(Math, lotsOfNumbers)
, which is a not-unreasonable way of getting the max number from an array.)
- …because function arguments are stored on the stack? – Bergi Commented Feb 16, 2017 at 2:18
- Well, yes, that's the piece of info I was missing :) – nrabinowitz Commented Feb 16, 2017 at 3:44
1 Answer
Reset to default 13Function arguments are put on the stack. You're trying to put a million arguments onto the stack, and that's more than the maximum stack size. So the error message is very relevant to the reason for the error.
本文标签:
版权声明:本文标题:javascript - Why does apply with too many arguments throw "Maximum call stack size exceeded"? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741324805a2372411.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论