Originally posted by Katrina Owen:
I am completely new to JavaScript, and am currently trying to wrap my head around the calling of functions without their trailing parentheses, like so:
?
That does not call the function, it merely assigns the function to the onload property of the window.
Functions in JavaScript are
first-class objects that can be referenced just like any other object. They can be passed as parameters or assigned to properties as you are doing here.
Then there is the other variation on this:
I think you mean:
This creates an anonymous function using a function literal and assigns it to the onload property.
How do you know when to tack on those parentheses?
When you want to invoke the function. Think of the trailing parens as the "invocation operator".
how do you know you are dealing with a function (besides just remembering the fact)
Again functions are just data types like any other object. Any reference in JavaScript can be to any type of JavaScript object: a date, a
string, a number, a DOM element, and even a function.
[ July 22, 2007: Message edited by: Bear Bibeault ]