JavaScript recursion: Maximum call stack size exceeded

前端 未结 4 807
醉话见心
醉话见心 2021-02-13 02:29

I have a recursive function for moving some circles on a canvas. Overed circle is enlarged (zoom in) and all the other circles is pushed away. Pushed circles push other circles

4条回答
  •  庸人自扰
    2021-02-13 03:11

    1) I can not implement iteration because of unknown count of operations needed;

    Well, I have not looked at your code, but a general avoidance of linear recursion (you have a linear one here) looks like this:

    while (1 == 1) {
        if (breakcondition)
            break;
        doSomeCode()
    }
    

    So you do not have to know the exact number of iterations like in the for- loop case.

提交回复
热议问题