Maximum call stack size exceeded error

后端 未结 30 2543
独厮守ぢ
独厮守ぢ 2020-11-21 23:51

I am using a Direct Web Remoting (DWR) JavaScript library file and am getting an error only in Safari (desktop and iPad)

It says

Maximum call

相关标签:
30条回答
  • 2020-11-22 00:30

    In my case, click event was propagating on child element. So, I had to put the following:

    e.stopPropagation()

    on click event:

     $(document).on("click", ".remove-discount-button", function (e) {
               e.stopPropagation();
               //some code
            });
     $(document).on("click", ".current-code", function () {
         $('.remove-discount-button').trigger("click");
     });
    

    Here is the html code:

     <div class="current-code">                                      
          <input type="submit" name="removediscountcouponcode" value="
    title="Remove" class="remove-discount-button">
       </div>
    
    0 讨论(0)
  • 2020-11-22 00:31

    The issue in my case is because I have children route with same path with the parent :

    const routes: Routes = [
      {
        path: '',
        component: HomeComponent,
        children: [
          { path: '', redirectTo: 'home', pathMatch: 'prefix' },
          { path: 'home', loadChildren: './home.module#HomeModule' },
        ]
      }
    ];
    

    So I had to remove the line of the children route

    const routes: Routes = [
      {
        path: '',
        component: HomeComponent,
        children: [
          { path: 'home', loadChildren: './home.module#HomeModule' },
        ]
      }
    ];
    
    0 讨论(0)
  • 2020-11-22 00:32

    Sometimes happened because of convert data type , for example you have an object that you considered as string.

    socket.id in nodejs either in js client as example, is not a string. to use it as string you have to add the word String before:

    String(socket.id);
    
    0 讨论(0)
  • 2020-11-22 00:33

    It means that somewhere in your code, you are calling a function which in turn calls another function and so forth, until you hit the call stack limit.

    This is almost always because of a recursive function with a base case that isn't being met.

    Viewing the stack

    Consider this code...

    (function a() {
        a();
    })();
    

    Here is the stack after a handful of calls...

    Web Inspector

    As you can see, the call stack grows until it hits a limit: the browser hardcoded stack size or memory exhaustion.

    In order to fix it, ensure that your recursive function has a base case which is able to be met...

    (function a(x) {
        // The following condition 
        // is the base case.
        if ( ! x) {
            return;
        }
        a(--x);
    })(10);
    
    0 讨论(0)
  • 2020-11-22 00:33

    In my case, two jQuery modals were showing stacked on top of each other. Preventing that solved my problem.

    0 讨论(0)
  • 2020-11-22 00:33

    Both invocations of the identical code below if decreased by 1 work in Chrome 32 on my computer e.g. 17905 vs 17904. If run as is they will produce the error "RangeError: Maximum call stack size exceeded". It appears to be this limit is not hardcoded but dependant on the hardware of your machine. It does appear that if invoked as a function this self-imposed limit is higher than if invoked as a method i.e. this particular code uses less memory when invoked as a function.

    Invoked as a method:

    var ninja = {
        chirp: function(n) {
            return n > 1 ? ninja.chirp(n-1) + "-chirp" : "chirp";
        }
    };
    
    ninja.chirp(17905);
    

    Invoked as a function:

    function chirp(n) {
        return n > 1 ? chirp( n - 1 ) + "-chirp" : "chirp";
    }
    
    chirp(20889);
    
    0 讨论(0)
提交回复
热议问题