From da78a9e329e272dedb2400b79a3bdeebff387d47 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:17 -0500 Subject: initial commit --- .../reference/errors/too_much_recursion/index.html | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 files/it/web/javascript/reference/errors/too_much_recursion/index.html (limited to 'files/it/web/javascript/reference/errors/too_much_recursion') diff --git a/files/it/web/javascript/reference/errors/too_much_recursion/index.html b/files/it/web/javascript/reference/errors/too_much_recursion/index.html new file mode 100644 index 0000000000..049ed04cf0 --- /dev/null +++ b/files/it/web/javascript/reference/errors/too_much_recursion/index.html @@ -0,0 +1,72 @@ +--- +title: 'InternalError: too much recursion' +slug: Web/JavaScript/Reference/Errors/Too_much_recursion +tags: + - Errore + - JavaScript +translation_of: Web/JavaScript/Reference/Errors/Too_much_recursion +--- +
{{jsSidebar("Errors")}}
+ +

The JavaScript exception "too much recursion" or "Maximum call stack size exceeded" occurs when there are too many function calls, or a function is missing a base case.

+ +

Message

+ +
Error: Spazio nello stack esaurito (Edge)
+InternalError: Troppa ricorsione (Firefox)
+RangeError: Dimensioni massime dello stack superate (Chrome)
+
+ +

Error type

+ +

{{jsxref("InternalError")}}.

+ +

Cos'è andato storto?

+ +

Una funzione che si chiama da sola si chiama funzione ricorsiva. Una volta che la condizione è soddisfatta, la funzione smette di chiamarsi. Questo si chiama caso di base.

+ +

In certi versi, la ricorsione è analoga ai cicli. Entrambi eseguono lo stesso codice più volte, ed entrambi richiedono una condizione(per evitare cicli infiniti,o in questo caso, ricorsioni infinite). Quando ci sono troppe chiamate, o manca il caso di base , JavaScript lancerà questo errore.

+ +

Esempi

+ +

Questa funzione ricorsiva si chiama 10 volte, secondo le condizioni d'uscita

+ +
function ciclo(x) {
+  if (x >= 10) // "x >= 10" condizione d'uscita
+    return;
+  // do stuff
+  ciclo(x + 1); // chiamata ricorsiva
+}
+ciclo(0);
+ +

Impostare questa condizione a valori estremamente alti non funzionerà:

+ +
function ciclo(x) {
+  if (x >= 1000000000000)
+    return;
+  // fà cose
+  ciclo(x + 1);
+}
+ciclo(0);
+
+// Errore Interno: troppa ricorsione
+ +

Alla funzione manca un caso base.Visto che non c'è condizione di uscita, la funzione chiama se stessa all'infinito.

+ +
function ciclo(x) {
+ // Manca caso base
+
+ciclo(x + 1); // Chiamata ricorsiva
+}
+
+ciclo(0);
+
+// Errore Interno: troppa ricorsione
+ +

Vedi anche

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