File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "functions in javascript" Watch "functions in javascript" New topic
Author

functions in javascript

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
hi,
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="http://keelypavan.blogspot.com" target="_blank" rel="nofollow">http://keelypavan.blogspot.com</a>
Eric Pascarello
author
Rancher

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

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: functions in javascript