1、(function(){alert("hello");})()
2. Nameless function
Anonymous functions, one of which may be to generate references to new function objects, are mainly used for definitions.
Another use is for some callback functions in js that cannot contain parameters.
The obvious example is setInterval. I think this is a function that many people have a headache about, especially when you want to add parameters to the callback function.
And the most troublesome thing is that DHTML is not a standard specified by w3c, so the setInterval parameter table given by different browsers is still different. . .
As for the two browsers I tested (IE kernel, webkit kernel)
IE:setInvterval(function, msecond [,lang]);
chrome:setInterval(function, msecond [, pram1, pram2, ....]);
In other words, chrome allows adding parameters to functions, and the parameter table is at the last edge. However, the function of the last parameter of IE is to indicate the type of scripting language used, because IE also supports other scripting languages such as vbs in addition to js.
In order to solve compatibility, no-name functions have to be used. . .
[code]
function test(yourArg)
{
var arg = yourArg;
setInterval(function(){callback(arg)}, time);
}
[html]
2. Nameless function
Anonymous functions, one of which may be to generate references to new function objects, are mainly used for definitions.
Another use is for some callback functions in js that cannot contain parameters.
The obvious example is setInterval. I think this is a function that many people have a headache about, especially when you want to add parameters to the callback function.
And the most troublesome thing is that DHTML is not a standard specified by w3c, so the setInterval parameter table given by different browsers is still different. . .
As for the two browsers I tested (IE kernel, webkit kernel)
IE:setInvterval(function, msecond [,lang]);
chrome:setInterval(function, msecond [, pram1, pram2, ....]);
In other words, chrome allows adding parameters to functions, and the parameter table is at the last edge. However, the function of the last parameter of IE is to indicate the type of scripting language used, because IE also supports other scripting languages such as vbs in addition to js.
In order to solve compatibility, no-name functions have to be used. . .
[code]
function test(yourArg)
{
var arg = yourArg;
setInterval(function(){callback(arg)}, time);
}
[html]