aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 437
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: 60080
    
  65

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: 437
bear, i still can't understand it ? do you mind to give me better example?
Eric Pascarello
author
Rancher

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



Eric
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 437
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: 60080
    
  65

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: 437
thanks for guidance , bear , i'm understand it better now
 
wood burning stoves
 
subject: what is "function" here means ?
 
Similar Threads
what is this function() means in ajax ?
functions in javascript
Having trouble with a javascript assignment
XSLT question: about xsl:key() functions.
jQuery newbie doubts