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 9180117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:58:02+00:00 2026-06-17T17:58:02+00:00

I am tring to emulate static members in javascript. consider this code: // option

  • 0

I am tring to emulate static members in javascript.

consider this code:

 // option A for static members:

     // constructor...
  function Person(name) {

      this.firstName=name;        
  }

  Person.count=0;              //  like a static member...
  var p=new Person("Dan");
  Person.count++;

  alert(Person.count);   // 1;

and now this one:

  //  option B for static members:
          // constructor..
  function Person(name) {

      this.firstName=name;
      Person.prototype.count++;     

  }

  Person.prototype.count=0;        //  like a static member...
  var p=new Person("Dan");
  alert(Person.prototype.count);   // 1;

  //       ... 

so, is it true to say that the main difference between those two, is that in the second example you can refer to the static member from the constuctor (due to the prototype decleration), while in the first example you can’t ?

  • 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-17T17:58:03+00:00Added an answer on June 17, 2026 at 5:58 pm

    In both examples you can get to it from within the constructor. The difference is in whether you can get to it through one of your objects.

    Option A:

    function Person (name) {
        this.firstName = name;
        Person.count++;
    }
    
    Person.count = 0;
    var p = new Person("Dan")
    
    console.log(Person.count) // 1
    console.log(p.count) // undefined
    

    Option B:

    function Person (name) {
        this.firstName=name;
        Person.prototype.count++;     
    }
    
    Person.prototype.count = 0;
    var p = new Person("Dan");
    
    console.log(Person.prototype.count) // 1
    console.log(p.count) // 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to emulate a web browser in order to execute JavaScript code
I have been trying to emulate static properties in javascript. It has been mentioned
I'm getting in trouble. I'm trying to emulate the call Application.Run using Application.DoEvents... this
I am using this jQuery Tooltip plugin . I am trying to emulate the
I'm trying to emulate the behavior of this drag n drop found here How
Hi i was trying to emulate a post created from javascript in a site
I am trying to emulate click events in Swing using following code: event =
I'm trying to emulate this graph: If I have a correlation matrix how can
I'm trying to emulate the LIKE operator in LINQ to Objects. Here my code:
So I'm trying to emulate the way in which the standard Apple code works

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.