diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:17 -0500 |
commit | da78a9e329e272dedb2400b79a3bdeebff387d47 (patch) | |
tree | e6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/it/web/javascript/reference/errors/too_much_recursion | |
parent | 1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff) | |
download | translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2 translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip |
initial commit
Diffstat (limited to 'files/it/web/javascript/reference/errors/too_much_recursion')
-rw-r--r-- | files/it/web/javascript/reference/errors/too_much_recursion/index.html | 72 |
1 files changed, 72 insertions, 0 deletions
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 +--- +<div>{{jsSidebar("Errors")}}</div> + +<p>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.</p> + +<h2 id="Message">Message</h2> + +<pre class="syntaxbox notranslate">Error: Spazio nello stack esaurito (Edge) +InternalError: Troppa ricorsione (Firefox) +RangeError: Dimensioni massime dello stack superate (Chrome) +</pre> + +<h2 id="Error_type">Error type</h2> + +<p>{{jsxref("InternalError")}}.</p> + +<h2 id="Cosè_andato_storto">Cos'è andato storto?</h2> + +<p>Una funzione che si chiama da sola si chiama <em>funzione ricorsiva</em>. Una volta che la condizione è soddisfatta, la funzione smette di chiamarsi. Questo si chiama <em>caso di base.</em></p> + +<p>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.</p> + +<h2 id="Esempi">Esempi</h2> + +<p>Questa funzione ricorsiva si chiama 10 volte, secondo le condizioni d'uscita</p> + +<pre class="brush: js notranslate">function ciclo(x) { + if (x >= 10) // "x >= 10" condizione d'uscita + return; + // do stuff + ciclo(x + 1); // chiamata ricorsiva +} +ciclo(0);</pre> + +<p>Impostare questa condizione a valori estremamente alti non funzionerà:</p> + +<pre class="brush: js example-bad notranslate">function ciclo(x) { + if (x >= 1000000000000) + return; + // fà cose + ciclo(x + 1); +} +ciclo(0); + +// Errore Interno: troppa ricorsione</pre> + +<p>Alla funzione manca un caso base.Visto che non c'è condizione di uscita, la funzione chiama se stessa all'infinito.</p> + +<pre class="brush: js example-bad notranslate">function ciclo(x) { + // Manca caso base + +ciclo(x + 1); // Chiamata ricorsiva +} + +ciclo(0); + +// Errore Interno: troppa ricorsione</pre> + +<h2 id="Vedi_anche">Vedi anche</h2> + + + +<ul> + <li>{{Glossary("Recursion")}}</li> +</ul> |