...

View Full Version : Need help understanding unusual syntax please



bcatt
06-10-2008, 11:32 PM
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?

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum