This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes what is 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 "what is "function" here means ?" Watch "what is "function" here means ?" New topic
Author

what is "function" here means ?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 457
hi, good day ,

can expert here explain what is "function" means here?




how to use it ? and when should we use it ?

can someone give better example ?

thank you for guidance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63207
    
  69

Functions are 1st-class objects in Javascript and as such can be declared as literals. The syntax you are seeing here is creating a function literal and assigning it to the onreadystate property of an object.

This construct is also sometimes termed a "closure".
[ August 02, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 457
bear, i still can't understand it ? do you mind to give me better example?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15385
    
    6
Basic example of extending objects with prototype:



Eric
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 457
great , eric .. thanks for useful sample ,

meaning i can assume it as class in java ? something like following for this sample

message.informUser = function(){ this.text = null;}

as following prototype ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63207
    
  69

Not really.

Take the following example:



this is similar to:



In the first example no separate, named function is created -- an unnamed function is created using a function literal. In the second, a reference to a named function is stored.

In either example, a reference to a function that says "hi!" is stored int he someProperty property of someObject.

(There is a difference between the 2 examples regarding how variables are scoped, but that's a nuance that might just be confusing at this point).
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 457
thanks for guidance , bear , i'm understand it better now
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: what is "function" here means ?
 
jQuery in Action, 3rd edition