aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes prototype question 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 "prototype question" Watch "prototype question" New topic
Author

prototype question

Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
Do Function and Object have different prototype? thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Object has no prototype.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
but I've seen quite a lot of snippet like object.prototype.whatever or Function.prototype.blah.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Only if object is a function.
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
how can an object be a function? could you please explain more about this? thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

In JavaScript, functions are first class objects. So every function is an object.

Just like any other object type, functions can be:
  • Declared with literals.
  • Assigned to variables.
  • Passed as a parameter to a function.
  • Be returned as the value of a function.
  • And so on...
  • Paul Clapham
    Bartender

    Joined: Oct 14, 2005
    Posts: 18989
        
        8

    I thought it was about time for me to learn jQuery, so I started off by downloading it. However since I just clicked on the "Download" link, the code appeared in my browser. And right in the middle of the page I saw this:



    Probably there's more going on here than meets the eye, but possibly this sort of thing was what Hendra was asking about.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61766
        
      67

    Get ready to have your mind blown: Object is a function! In fact, it's the constructor for instances of all things Object.

    In fact, anything that you can operate on with the new operator is a constructor function.

    Welcome to functional programming.

    When someone says that JavaScript != Java, few people have an inkling of how deep the differences go.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61766
        
      67

    The promo for Secrets of the JavaScript Ninja isn't until early December, but anyone with these types of questions really needs to read chapters 3, 4, 5, and 6. They lay bare what it means for JavaScript to be a functional language, and what's really going on when we use functions and objects in JavaScript.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: prototype question