“Stack overflow in line 0” on Internet Explorer

后端 未结 13 2077
时光取名叫无心
时光取名叫无心 2020-12-14 00:48

I realise this is not the ideal place to ask about this in terms of searchability, but I\'ve got a page whose JavaScript code throws \"Stack overflow in line 0\" errors when

13条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 01:08

    In my case I had two functions a() and b(). First was calling second and second was calling first one:

    var i = 0;
    function a() { b(); }
    function b() {
      i++; 
      if (i < 30) {
        a();
      }
    }
    
    a();
    

    I resolved this using setTimeout:

    var i = 0;
    function a() { b(); }
    function b() {
      i++; 
      if (i < 30) {
        setTimeout( function() {
          a();
        }, 0);
      }
    }
    
    a();
    

提交回复
热议问题