The example in this article describes how JavaScript implements passing parameters to the setTimeout execution code. Share it with everyone for your reference. The specific analysis is as follows:
The setTimeout function is the most critical function in JavaScript to achieve dynamic effects. But yesterday when I was writing code, I discovered that when the first parameter is a function call, parameters cannot be passed to the called function. This is really a very serious problem. It took me a long time to find out the problem, and I wasted a lot of time. .
I checked online later and found that this is actually a BUG in IE. There are many solutions, and I think the most awesome one is to rewrite the setTimeout function. . . This is too much trouble. . Here is a very simple method recommended. Just add the function{} keyword before the function you want to call.
function ShowMsg(x,y) { } setTimeout(funtion(){ShowMsg(x,y)},1000);
This conveniently solves the problem of not being able to pass parameters.
I hope this article will be helpful to everyone’s JavaScript programming design.