Does calling setTimeout clear the callstack?

后端 未结 3 1022
遥遥无期
遥遥无期 2020-12-03 17:31

Can a stack overflow be avoided in javascript by using the setTimeout method to call a function instead of calling it directly? My understanding of setTimeout is that it sho

3条回答
  •  青春惊慌失措
    2020-12-03 18:13

    Async invocations, such as those from setTimeout, do indeed generate a new callstack.

    It's not entirely clear what you're describing when you say "When i look in the callstack of both chrome and IE it seems that the setTimeout calls are waiting for the function call to return." But, one thing you can do is put a breakpoint inside of a function called by setTimeout, and see that the callstack is empty.

提交回复
热议问题