Does a function like this slow performance or is it considered bad practice?
setInterval(function(){
if(something){
do something
}
}, 100);
Seems to me it would be bad to have something constantly running in the background.
Does a function like this slow performance or is it considered bad practice?
setInterval(function(){
if(something){
do something
}
}, 100);
Seems to me it would be bad to have something constantly running in the background.
Share Improve this question asked Oct 5, 2017 at 22:26 NewCodeManNewCodeMan 2276 silver badges17 bronze badges 2- If there has to be sth run regularily, what other way would be there?? – Jonas Wilms Commented Oct 5, 2017 at 22:34
- I don't know. I'm a beginner :o) but I will learn more – NewCodeMan Commented Oct 5, 2017 at 22:36
1 Answer
Reset to default 8It is running a set of instructions every so many milliseconds, so it can "slow things down," depending on how intensive the instructions are and how many other instructions the user is running from other processes or on your webpage.
It is bad practice if not necessary. If your app is an app that does a thing every so many milliseconds, then that is one way to acplish it. If you are resigning to use it because you just can't figure out the correct way of doing your task, you should spend time to find and implement the correct way of doing your task, instead of harassing the user's CPU cycles.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745390607a4625644.html
评论列表(0条)