/ / setTimeout y jQuery: No se detectó RangeError: se excedió el tamaño máximo de la pila de llamadas [duplicado] - javascript, jquery, function, settimeout

setTimeout y jQuery: No se detectó RangeError: Se excedió el tamaño máximo de la pila de llamadas [duplicado] - javascript, jquery, function, settimeout

Estoy tratando de llamar a mi clase cuando se carga la página, comoAdemás de recargar los resultados cada X segundos, sin embargo, siguiendo los tutoriales de setTimeout, jquery parece arrojarme un error que no entiendo teniendo en cuenta su sintaxis.

Intervalo no detectado: se ha excedido el tamaño máximo de pila de llamadas

var rand = function() {
return Math.random().toString(36).substr(2);
};

lhc();

function lhc(){
$("#lhcb a").each(function() {
var rawlink = $(this).attr("href");
var link = encodeURIComponent( rawlink );
var token = rand();
var href = $(this).prop("href");
var proceed = $.getJSON( "lhc/link.php?link=" + link + "&a=c", function( data ) {
if ( data.proceed == "true" ) {
return true;
} else {
return false;
}
}).error(function(e) { alert("error"); console.log(e);});
if ( href.match("^javascript:") ) {
proceed = false;
}
if ( rawlink.charAt(0) != "#" ) {
if ( proceed ) {
$(this).after( " <span style="font-size:xx-small;">( Hits: <span id="" + token + ""></span> )</span>" );
$.getJSON( "lhc/link.php?link=" + link + "&a=q", function( data ) {
$("#" + token).html(data["hits"]);
}).error(function(e) { alert("error"); console.log(e);});
$(this).attr( "href", "lhc/link.php?link=" + link + "&a=g" );
}
}

});
setTimeout(lhc(), 5000);
}

Respuestas

26 para la respuesta № 1

Cambio

setTimeout(lhc(), 5000);

a

setTimeout(lhc, 5000);

Estás llamando a la función directamente sin unel tiempo de espera cuando agrega el paréntesis, y llamar a la función de inmediato dentro de la misma función se convierte rápidamente en un bucle sin fin que llena la pila


0 para la respuesta № 2

Puede ignorar el error si se ejecuta <script>window.onerror = function(){ return true;} </script> Y establecer setTimeout(lhc, 5000); algunos.