I have the following function
function hello() {
alert(\"hi!\");
}
Take this piece of code:
var elem = document.getElem
Do you want it to execute NOW? Then call it.
a=hello()
means "Call hello()
ASAP, and set its return value to a
".
On the other hand, a=hello
means "a
is an alias for hello
. If you call a()
, you get the same results as calling hello()
"
You use the latter for callbacks, etc, where you want to tell the browser what you want to happen after an event occurs. For example, you may want to say "call hello()
when the user clicks" (as in the example). Or, "When the AJAX query returns a result, call the callback()
function on the returned data".