diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/errors/too_much_recursion | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/errors/too_much_recursion')
| -rw-r--r-- | files/zh-cn/web/javascript/reference/errors/too_much_recursion/index.html | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/errors/too_much_recursion/index.html b/files/zh-cn/web/javascript/reference/errors/too_much_recursion/index.html new file mode 100644 index 0000000000..1671a5598a --- /dev/null +++ b/files/zh-cn/web/javascript/reference/errors/too_much_recursion/index.html @@ -0,0 +1,54 @@ +--- +title: 'InternalError: too much recursion' +slug: Web/JavaScript/Reference/Errors/Too_much_recursion +tags: + - InternalError + - recursion + - 内部错误 +translation_of: Web/JavaScript/Reference/Errors/Too_much_recursion +--- +<div>{{jsSidebar("Errors")}}</div> + +<h2 id="信息">信息</h2> + +<pre class="syntaxbox">InternalError: too much recursion +</pre> + +<h2 id="错误类型">错误类型</h2> + +<p>{{jsxref("InternalError","内部错误")}}.</p> + +<h2 id="什么地方出错了">什么地方出错了?</h2> + +<p>一个调用自身的函数被称作<em>递归函数</em>。一些情况下,递归函数类似于一个循环,都重复地执行一个代码段许多次,都需要一个条件(用于避免无尽循环或此处的无尽递归)。当出现过于深层的递归或无尽递归时,JavaScript将会抛出此错误。</p> + +<h2 id="示例">示例</h2> + +<p>根据递归终止的条件,该函数将递归地执行 10 次。</p> + +<pre class="brush: js">function loop(x) { + if (x >= 10) // "x >= 10" 是递归终止条件 + return; + // 进行一些操作... + loop(x + 1); // 递归调用 +} +loop(0);</pre> + +<p>将递归条件设置为一个极大的数值,将不能运行:</p> + +<pre class="brush: js example-bad">function loop(x) { + if (x >= 1000000000000) + return; + // 进行一些操作... + loop(x + 1); +} +loop(0); + +// InternalError: too much recursion</pre> + +<h2 id="相关页面">相关页面</h2> + +<ul> + <li>{{Glossary("Recursion","递归")}}</li> + <li><a href="/en-US/docs/Web/JavaScript/Guide/Functions#Recursion">Recursive functions</a></li> +</ul> |
