• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

functions in javascript

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pavan Keely
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You normally do something like that as a JavaScript closures. Search Google for more information.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic