Skip to content Skip to sidebar Skip to footer

Getting The “rangeerror: Maximum Call Stack Size Exceeded” Error

how can i add function on top of the already existing function? i'm using following way and it gives me error on resources.onload resource = document.getElementById(this.id);

Solution 1:

Move the onloadOthers and resources variables in a new closure, by prefixing the var keyword.

Currently, your code "recycles" these (global) variables, because they're declared in a non-local scope:

var onloadOthers;
function func() {
    onloadOthers = ...;
    resource.onload = function() {
        onloadOthers(); // Calls the global `onloadOthers` function.
    };
}
func(); // Defines `onloadOthers`func(); // Overwrites `onloadOthers`

By moving the variable to a local scope, all instances of the function will have an "own" onloadOthers variable, which solves the problem.

If you want to learn more about this topic, read How do JavaScript closures work?.

Post a Comment for "Getting The “rangeerror: Maximum Call Stack Size Exceeded” Error"