View Full Version : Need help understanding unusual syntax please

06-11-2008, 12:32 AM
I am working on a project based off the simile timeline (http://simile.mit.edu/timeline/), and am trying to understand the code so I can customize the interface. Many of the files in the API, such as this (http://simile.mit.edu/repository/timeline/trunk/src/webapp/api/timeline-api.js), contain functions that have me confused because of their syntax:

(function() {
//stuff that the function does

All I can guess is that it is a function within a function, but where is the outer function declared? I would expect something like:

function1 (function2() {
//stuff that the function does

Could someone please explain this to me?

06-11-2008, 12:44 AM
wrapping a function declaration in parenthesis and following the whole expression with the function call ('()') calls the function as soon as it is defined.