File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes functions in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "functions in javascript" Watch "functions in javascript" New topic

functions in javascript

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 361
i came across the following code in javascript.....

how and when function like these called, since the above funcion does not have any name.

thnx in advance

SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Pavan Keely
Ranch Hand

Joined: Jun 30, 2006
Posts: 62
Those are called anonymous functions. You can assign these function references to any variable. like,

var myFunc = function() {
//code here

and call that function like, myFunc();

If you don;t assign this function reference to any varible/object property, it's not much of use.

Pavan Keely<br /><a href="" target="_blank" rel="nofollow"></a>
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
You normally do something like that as a JavaScript closures. Search Google for more information.

I agree. Here's the link:
subject: functions in javascript
It's not a secret anymore!