1

Possible Duplicate:
Javascript: var functionName = function() {} vs function functionName() {}

I have code with functions defined in two ways:

var retrieveData = function (statusValue, statusText)
{
...
}


function retrieveData(statusValue, statusText) {
..
}


retrieveData(1,2);

Can someone explain what the difference is. Seems that the second way of setting up the function is much simpler.

Community
  • 1
  • 1
Dave Heart
  • 39
  • 4

1 Answers1

1

The 1st example creates a pointer to the function stored in the variable retrieveData, this way you can pass functions like any other variable and retrieve and use them dynamically. Other languages have similar constructs.

pokstad
  • 3,411
  • 3
  • 30
  • 39
  • okay I sorry to be dumb but what is the point of this in a simple script where I have a function and later want to call it. – Dave Heart Jun 12 '11 at 19:50
  • 1
    in that case it's overkill for a simple script, but javascript is used in very large bodies of code where this can be useful – pokstad Jun 12 '11 at 19:54