4

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 must specify a function name, not a function reference.

What's the difference been a JavaScript function name vs a function reference?

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

asked May 11, 2010 at 18:05
1
  • Can you provide a link to exactly where that documenation fragment is? Is it actually for the API itself, or is it for the Google javascript loader, or what? edit oh I found it. Commented May 11, 2010 at 18:10

5 Answers 5

1

function: function func() {}

function reference: func

function name: 'func'

outis
77.7k23 gold badges155 silver badges228 bronze badges
answered May 11, 2010 at 18:08
Sign up to request clarification or add additional context in comments.

Comments

1

A function name is a string ("alert"). A function reference is the function itself (alert).

answered May 11, 2010 at 18:07

5 Comments

so it would be callback="function_name" ?
If you're using auto-loading.
Yes, I'm using auto-loading. So is * callback="function_name"* correct?
If you're using auto-loading.
Any idea why google.com/jsapi?autoload={modules:[{name:%22maps%22,version:3,{other_params:%22sensor=false%22,callback:%22function_name%22}]} doesn't work then?
1

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() {}
answered May 11, 2010 at 18:08

Comments

0

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
answered May 11, 2010 at 18:10

1 Comment

The question makes sense if you read the snippet of documentation in context.
0

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).

answered May 11, 2010 at 18:07

2 Comments

so it would be callback=function_name or callback=function_name() ?
Neither: {callback: "function_name"}

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.