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

Related searches

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?

function: function func() {}

function reference: func

function name: 'func'

What is JavaScript, JavaScript is the Programming Language for the Web. JavaScript can update and change both HTML and CSS. JavaScript can calculate, manipulate and validate data. Start Building With JavaScript Today. Courses Led By Experts, No Previous Skills Required. Try It Free For 7 Days. From Beginner To Career-Ready.

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

What Is JavaScript? A Guide for Total Beginners, Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript Browse & Discover Thousands of Book Titles, for Less.

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() {}

Wat, Tech 101: What is JavaScript � JavaScript is a scripting language used to create and control dynamic website content, i.e. anything that moves, refreshes, or� JavaScript (/ ˈ dʒ ɑː v ə ˌ s k r ɪ p t /), often abbreviated as JS, is a programming language that conforms to the ECMAScript specification. JavaScript is high-level, often just-in-time compiled, and multi-paradigm.


// 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

If you liked this, you might also like Execute Program: interactive courses on TypeScript, Modern JavaScript, SQL, regular expressions, and more. Each course is� Introduction to JavaScript JavaScript Versus Java . JavaScript and Javaare two different computer languages, both developed in 1995. Java is an Using and Writing JavaScript . What makes JavaScript great is that it's not necessary to know how to write it to use it HTML Versus JavaScript . HTML

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

What is this? The JavaScript this keyword refers to the object it belongs to. It has different values depending on where it is used: In a method, this refers to the owner object. Alone, this refers to the global object. In a function, this refers to the global object. In a function, in strict mode, this is undefined.

Many Internet Web sites contain JavaScript, a scripting programming language that runs on the web browser to make specific features on the web page functional. If JavaScript has been disabled within your browser, the content or the functionality of the web page can be limited or unavailable.

How to enable JavaScript in your browser Nowadays almost all web pages contain JavaScript, a scripting programming language that runs on visitor's web browser. It makes web pages functional for specific purposes and if disabled for some reason, the content or the functionality of the web page can be limited or unavailable.

The dollar sign ($) and the underscore (_) characters are JavaScriptidentifiers, which just means that they identify an object in the same way a name would.  The objects they identify include things such as variables, functions, properties, events, and objects.

  • 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.
  • 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{modules:[{name:%22maps%22,version:3,{other_params:%22sensor=false%22,callback:%22function_name%22}]} doesn't work then?
  • The question makes sense if you read the snippet of documentation in context.
  • so it would be callback=function_name or callback=function_name() ?
  • Neither: {callback: "function_name"}