var my_new_function = function(){
----
};
window.setTimeout(my_new_function, 1600);
the above works properly without any errors.
when i use:
window.setTimeout("my_new_function()", 1600);
it’s working properly, but firebug is showing error :
my_new_function is not defined
in some articles about setTimeout, i found calling functions like in the 1st method, and in some other articles, i saw the other method.
which is more correct? and why is firebug showing such an error?
When you call the function with
You are setting the reference to the function.
The function in your second setTimeout example
needs to be evaluated when it is executed. When it is evaluated it is being executed in global scope. So if the function is in local scope the browser will not find it. [Sounds like this is your issue]
Seasoned developers will not recommend using strings in setTimeout since they need to be evaluated each time. All that means is it takes longer to execute.
Another option to call setTimeout is