Jump to content

Javascript Function Definition


toreachdeepak
 Share

Recommended Posts

What they're doing there is assigning the return value of an anonymous function to the variable. Here's an example of a use for it:

var Population = function() {  return xmlDoc.getElementsByTagName("person").length}();alert(Population); // Returns the amount of <person> nodes in the specified XML document

Notice the (); at the end. That's what's making the preceding function run. If they were absent, you'd have to apply them to the variable when using it:

var Population = function() {  return xmlDoc.getElementsByTagName("person").length};alert(Population());

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...