• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is "function" here means ?

 
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bear, i still can't understand it ? do you mind to give me better example?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for guidance , bear , i'm understand it better now
reply
    Bookmark Topic Watch Topic
  • New Topic