mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 23:44:06 +08:00
34 lines
1.9 KiB
HTML
34 lines
1.9 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<h2 id="信息">信息</h2>
|
||
<pre><code class="language-javascript">InternalError: too much recursion
|
||
</code></pre>
|
||
<h2 id="错误类型">错误类型</h2>
|
||
<p><a href="Reference/Global_Objects/InternalError" title='InternalError 对象表示出现在JavaScript引擎内部的错误。 例如: "InternalError: too much recursion"(内部错误:递归过深)。'><code>内部错误</code></a>.</p>
|
||
<h2 id="什么地方出错了">什么地方出错了?</h2>
|
||
<p>一个调用自身的函数被称作<em>递归函数</em>。一些情况下,递归函数类似于一个循环,都重复地执行一个代码段许多次,都需要一个条件(用于避免无尽循环或此处的无尽递归)。当出现过于深层的递归或无尽递归时,JavaScript将会抛出此错误。</p>
|
||
<h2 id="示例">示例</h2>
|
||
<p>根据递归终止的条件,该函数将递归地执行 10 次。</p>
|
||
<pre><code class="language-javascript">function loop(x) {
|
||
if (x >= 10) // "x >= 10" 是递归终止条件
|
||
return;
|
||
// 进行一些操作...
|
||
loop(x + 1); // 递归调用
|
||
}
|
||
loop(0);</code></pre>
|
||
<p>将递归条件设置为一个极大的数值,将不能运行:</p>
|
||
<pre><code class="language-js example-bad">function loop(x) {
|
||
if (x >= 1000000000000)
|
||
return;
|
||
// 进行一些操作...
|
||
loop(x + 1);
|
||
}
|
||
loop(0);
|
||
|
||
// InternalError: too much recursion</code></pre>
|
||
<h2 id="相关页面">相关页面</h2>
|
||
<ul>
|
||
<li><a class="glossaryLink" href="/en-US/docs/Glossary/Recursion" title="递归: An act of a function calling itself. Recursion is used to solve problems that contain smaller sub-problems. A recursive function can receive two inputs: a base case (ends recursion) or a recursive case (continues recursion).">递归</a></li>
|
||
<li><a href="/en-US/docs/Web/JavaScript/Guide/Functions#Recursion">Recursive functions</a></li>
|
||
</ul>
|
||
</article> |