Killing a JavaScript function which runs infinite

前端 未结 6 470
难免孤独
难免孤独 2021-01-19 00:04

As an example

var runInfinite = function(){
    while(1)
    {
       // Do stuff;
    }
};

setTimeout(runInfinite, 0);

Is it possible to

6条回答
  •  梦毁少年i
    2021-01-19 00:47

    The answer is no. Since JavaScript is single-threaded ( unless you are using some less common implementation which I doubt ) nothing can break a loop ( or any other block of code ) from outside.

提交回复
热议问题