I\'m reading the Google Maps API and it states that the:
\"callback: The function to call once the script has loaded. If using the Auto-loading feature, this
Well, perhaps what that bit of documentation means to say is that the "name" it expects should be a string containing the name of a function, instead of a "bare" function name (which is a reference to a function) or a function instantiation/definition expression.
edit OK I see what the deal is. This really isn't a Google Maps thing, it's the Google Javascript loader toolkit. The API does indeed want a string, which makes perfect sense since the function you want to call is inside the code that you're loading, and therefore you can't have a reference to it from the calling environment.
google.load("feeds", "1", {"callback" : "someFunctionName"});
It would make no sense to write:
google.load("feeds", "1", {"callback" : someFunctionName});
because "someFunctionName" used like that — as a reference to something — could not possibly be a reference to the right function (if it's defined at all).
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
function: function func() {}
function reference: func
function name: 'func'
A function name is a string ("alert"
). A function reference is the function itself (alert
).
The name of a function is a string such as 'foo' in this case:
function foo() {}
A reference to a function is any variable that is set to the value of the function itself (not the result of calling it).
Functions in Javascript can be anonymous - you can have a reference to a function that has no name.
var bar = function() {}