From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/errors/too_much_recursion/index.html | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/errors/too_much_recursion/index.html (limited to 'files/zh-cn/web/javascript/reference/errors/too_much_recursion') 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 +--- +
{{jsSidebar("Errors")}}
+ +

信息

+ +
InternalError: too much recursion
+
+ +

错误类型

+ +

{{jsxref("InternalError","内部错误")}}.

+ +

什么地方出错了?

+ +

一个调用自身的函数被称作递归函数。一些情况下,递归函数类似于一个循环,都重复地执行一个代码段许多次,都需要一个条件(用于避免无尽循环或此处的无尽递归)。当出现过于深层的递归或无尽递归时,JavaScript将会抛出此错误。

+ +

示例

+ +

根据递归终止的条件,该函数将递归地执行 10 次。

+ +
function loop(x) {
+  if (x >= 10) // "x >= 10" 是递归终止条件
+    return;
+  // 进行一些操作...
+  loop(x + 1); // 递归调用
+}
+loop(0);
+ +

将递归条件设置为一个极大的数值,将不能运行:

+ +
function loop(x) {
+  if (x >= 1000000000000)
+    return;
+  // 进行一些操作...
+  loop(x + 1);
+}
+loop(0);
+
+// InternalError: too much recursion
+ +

相关页面

+ + -- cgit v1.2.3-54-g00ecf