Here You can view an example, probably better than every word:
var // temporary scope variable declaration
myfunc // variable name (as function referer)
=
function(){}; // anonymous function
alert(myfunc.name);
// empty string because myfunc
// is a reference of an
// anonymous function
// ---------------------------- //
function // temporary scope function declaration
myotherfunc(){};// "the" myotherfunc function
alert(myotherfunc.name);
// string "myotherfunc" because
// myotherfunc is not a reference
// but exactly a function
So, an anonymous function has some limit, as I said on my old post but if You need a simple, tiny function that you're not using as class, You could declare anonymous function even inside a for loop
for(var f = function(){}, a = [1,2,3], b = a.length; b > 0; b--)
// do stuff
but if You need a class or a more complex function I suggest to use the "old classic" way:
function f(){
// do stuff
}
That's all, You should remember that first example doesn't work,
No comments:
Post a Comment