how to catch a “Maximum call stack size exceeded” error?

前端 未结 4 1287
走了就别回头了
走了就别回头了 2021-01-14 17:58
  try {
     requestAnimationFrame(function re(){
       re();
     })}
  catch (e){
       console.log(e);
     }

I tried above code in console, i

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 18:27

    You are calling the same function within the function re() inside your requestAnimationFrame() function. A correct way would be as follows:

    function re(){
        //code here
        requestAnimationFrame(re); //loop back to start
    }
    

提交回复
热议问题