aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/javascript/reference/errors/too_much_recursion
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/zh-tw/web/javascript/reference/errors/too_much_recursion
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/zh-tw/web/javascript/reference/errors/too_much_recursion')
-rw-r--r--files/zh-tw/web/javascript/reference/errors/too_much_recursion/index.html50
1 files changed, 50 insertions, 0 deletions
diff --git a/files/zh-tw/web/javascript/reference/errors/too_much_recursion/index.html b/files/zh-tw/web/javascript/reference/errors/too_much_recursion/index.html
new file mode 100644
index 0000000000..1708683ffa
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/errors/too_much_recursion/index.html
@@ -0,0 +1,50 @@
+---
+title: 'InternalError: too much recursion'
+slug: Web/JavaScript/Reference/Errors/Too_much_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>(recursive function)。在某些方面,遞迴和迴圈很像。它們都需要在指定條件(以避免無窮迴圈,或是本例的無窮遞迴)下,重複執行數次相同的程式碼。如果遞迴執行太多次、或成為無窮遞迴的話,JavaScript 就會出現這個錯誤。</p>
+
+<h2 id="實例">實例</h2>
+
+<p>以下的遞迴函式,會根據終止條件,而運行十次。</p>
+
+<pre class="brush: js">function loop(x) {
+ if (x &gt;= 10) // "x &gt;= 10" 是終止條件
+ return;
+ // do stuff
+ loop(x + 1); // 遞迴呼叫
+}
+loop(0);</pre>
+
+<p>如果把終止條件的次數設得太高,函式就不會運作了:</p>
+
+<pre class="brush: js example-bad">function loop(x) {
+ if (x &gt;= 1000000000000)
+ return;
+ // do stuff
+ loop(x + 1);
+}
+loop(0);
+
+// InternalError: too much recursion</pre>
+
+<h2 id="參見">參見</h2>
+
+<ul>
+ <li>{{Glossary("Recursion")}}</li>
+ <li><a href="/zh-TW/docs/Web/JavaScript/Guide/Functions#Recursion">遞迴函式</a></li>
+</ul>