alex escreveu:
> I am so confused with these three concept,who can explained it?thanks
> so much?
They have the same results.
> var f= new Function("x", "y", "return x * y");
I don't like it, for me it's just a masked "eval".
> function f(x,y){
> return x*y
> }
A _named_ function which becomes by default a local variable.
> var f=function(x,y){
> return x*y;
> }
An _anonymous_ function, that is forced to be local.
The only difference I found between being anonymous or not is showed bellow:
#Named function
(function Func(arg){
/* the variable "Func" just exists inside the function body, and it
also receives a name (for me stills not very useful) */
alert(Func);
}());
//but outside of the function body Func doesn't exists
alert(window.Func);
The parenthesis create a kind of closure ("closure" for me is enough by
just enclosing a variable).
#Anonymous function
var Func;
(Func = function(){
/* the only way to access the own function is by using the callee or
the "Func" variable */
alert(arguments.callee);
})();
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com