If I'm getting an infinite loop and find the error stepping throug开发者_StackOverflow中文版h the code, how do I then stop it so that I can reload the page with fixed code?
A. For recursive infinite loops:
There should always be some variable name that contains the function that is being called recursively, regardless of whether the function is private or global.
To stop the recursion, run a code snippet in the console that sets the variable containing the function to an empty function. So if your code is like this:
function doLoop() {
function privateFunction() {
privateFunction();
}
privateFunction();
}
Then your code snippet would be this:
privateFunction = function(){}
B. For for, and while loops:
Write a line that sets the exit condition to true. In this case, your code to put in the console could be "i = 6":
var n = 5
for (var i = 0; i < n; ){
var x = 1;
}
精彩评论