JavaScript: what's the difference between a function name and a function?

I am reading the Google Maps API and declaring that:

"callback: The function to call once the script has loaded. If using the Auto-loading feature, this must specify a function name, not a function reference. 

What is the difference between a JavaScript function name and a function reference?

http://code.google.com/apis/ajax/documentation/#GoogleLoad

+4
source share
5 answers

: function func() {}

: func

function name: 'func'

+1
source

The function name is a string ( "alert" ). A functional link is the function itself ( alert ).

+1
source

The function name is a string such as "foo" in this case:

 function foo() {} 

A function reference is any variable that is set to the value of the function itself (and not the result of its call).

Functions in Javascript can be anonymous - you may have a link to a function that does not have a name.

 var bar = function() {} 
+1
source

Well, perhaps this means that it means that the โ€œnameโ€ that it expects should be a string containing the name of the function, instead of the โ€œbareโ€ name of the function (which is a reference to the function) or an expression to create / define the function.

Change OK. I see what a deal it is. It really is not Google Maps, it is a tool for downloading Google Javascript. The API really wants a string that makes perfect sense, because the function you want to call is inside the loadable code, and therefore you cannot reference it from the calling environment.

 google.load("feeds", "1", {"callback" : "someFunctionName"}); 

It makes no sense to write:

 google.load("feeds", "1", {"callback" : someFunctionName}); 

because "someFunctionName" is used as this - as a reference to something; cannot be a reference to the correct function (if one is defined at all).

0
source

Nothing.

 // f1 :: function name function f1(a) { return a*a; } // f2 :: reference to an anonymous function var f2 = function(a) { return a*a; } // f3 :: a reference to the first function var f3 = f1; // these are equivalent. The second one calls into // a different actual function. f1(3); // 9 f2(4); // 16 f3(5); // 25 
0
source

Source: https://habr.com/ru/post/1309455/


All Articles