Answer the question
In order to leave comments, you need to log in
Why did safari start eating all the resources?
Why, after running Safari, does it eat all the CPU? And does not respond to the cmd + q command, writes that "Safari (does not respond)"? Although if you enter under the "Guest" account, then everything is fine. And the load appeared just suddenly, did not install anything. I have already removed all extensions from the browser, and even removed many software programs, but nothing helps. It can only be closed by force.
Here is such a load
And this is after the command cmd + q
Answer the question
In order to leave comments, you need to log in
The problem was solved by creating a new user account, and the old account was deleted, since it was still stupid.
Because all the functions passed to setTimeout are called after the loop is completed - and the value of i by that moment will be equal to 10.
How to fix it? It is possible like this:
for (var i = 0; i < 10; i++) {
setTimeout(function() {
alert(+this);
}.bind(i), 100);
}
for (let i = 0; i < 10; i++) {
setTimeout(function() {
alert(i);
}, 100);
}
for (var i = 0; i < 10; i++) {
setTimeout(function(i) {
alert(i);
}, 100, i);
}
for (var i=0; i < 10; i++) {
setTimeout(function() {
alert(i++);
}, 100);
}
i = 0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question