Maximum call stack size exceeded error

后端 未结 30 2581
独厮守ぢ
独厮守ぢ 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: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);
    

提交回复
热议问题