Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is "function" here means ?

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bear, i still can't understand it ? do you mind to give me better example?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic example of extending objects with prototype:



Eric
 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for guidance , bear , i'm understand it better now
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic