Home  >  Article  >  Web Front-end  >  JavaScript implements method of passing parameters to setTimeout execution code_javascript skills

JavaScript implements method of passing parameters to setTimeout execution code_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:03:341069browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn