Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:40:39+00:00 2026-06-01T10:40:39+00:00

I agree that Functions are objects in JS. When using a Function as a

  • 0

I agree that Functions are objects in JS. When using a Function as a constructor we can add properties to the object create by adding these properties to the prototype property on the function. This is what I tried:

var Mammal = function(name) {
    this.name = name;
};

var Cat = function(name) {
    this.saying = 'meow';
};

Cat.prototype = new Mammal();

Cat.prototype.display = function() {
    console.log('I display Cats');
};

//This is what I find hard to digest
Cat.display = function() {
    console.log('I display cats but at the top level');
};

What I find hard to grasp is the commented portion. I was just trying to picture what goes where and this particular part I don’t understand. I mean if I had to write a function and do something like this while defining the function what would be the syntax like?
If I try something like the following:

function demo() {
    this.saying = function() {
        console.log('I display cats but at the top level');
    };
};

The variable this here refers to the DOMWindow. How do I achieve the above thing within a function definition.

I am a total newbie to JS. I apologize for any ignorance on my part.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:40:40+00:00Added an answer on June 1, 2026 at 10:40 am

    Those are analogous to static methods in class based objects. That is, the method can only be accessed from the constructor, not from the instance itself.

    A good example of this ìs jQuery.get() You can’t do

    $('.someclass').get(myUrl);
    

    You have to use

    $.get(myUrl);
    

    However, if you do need to access the static method from an instance, you have two options

    var cat = new Cat('catName');
    cat.constructor.display();
    Cat.display();
    

    http://jsfiddle.net/c39bW/

    Not that your constructor property for Cat is broken, when you setup inheritance, you should fix the Cat.prototype.constructor to point back to Cat, see my jsFiddle above. Also, you’re not calling the base constructor (Mammal) from Cat’s constructor. For a tutorial on the minimal requirements for inheritance, see http://js-bits.blogspot.com/2010/08/javascript-inheritance-done-right.html

    A good example as to when static properties are useful is when an object needs to keep track of how many times it has been instantiated, you can’t do that at an instance level;

    function Tracker() {
       this.constructor.count++;
    }
    
    Tracker.count = 0;
    
    Tracker.getCount = function() {
         return Tracker.count;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Sencha touch 2. I have store that load from existing js object:
Is their a way to use a non-member non-friend function on an object using
I have a function that returns an NSError object by reference: NSData *foo(NSData *foo,
Most mathematicians agree that: e πi + 1 = 0 However, most floating point
Most people would agree that internationalizing an existing app is more expensive than developing
I think most C++ programmers here would agree that polluting the global namespace is
I'm curious about OpenID. While I agree that the idea of unified credentials is
I really enjoyed Jeff's post on Spartan Programming . I agree that code like
I agree, that programming against interfaces is a good practice. In most cases in
Windbg fans claim that it is quite powerful and I tend to agree. But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.