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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:58:30+00:00 2026-06-15T14:58:30+00:00

I can define a class in JavaScript like this: var appender = function (elements,

  • 0

I can define a class in JavaScript like this:

var appender = function (elements, func) {
    this.Prop = something;
    staticProp = something_else;
};

Am I right? Well then, how can I create a static field in this class? And how can I access that field inside the class? I mean I want a field that be shared between all instances from the class.

var ap1 = new appender();
var ap2 = new appender();
ap1.Prop = something1;
ap2.Prop = something2;
var t = ap1.Prop == ap2.Prop; // true
ap1.staticProp = something_static;
var s = ap2.staticProp = something_static; // I want to this returns true. how can I?
  • 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-15T14:58:32+00:00Added an answer on June 15, 2026 at 2:58 pm

    This is not answered so easily. It won’t behave like a static var you know from other languages such as Java etc.

    What you can do is append it to the function, like such:

    appender.staticProp = 3
    

    That means that within the function you have to reference it using the Function name:

    var Person = function(name) {
       this.name = name;
    
       this.say = function() {
           console.log( Person.staticVar );
       }
    }
    
    Person.staticVar = 3;
    

    So it allows you to append variables that are somewhat static. But you can only reference them as shown above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I research OOP-part of Scheme. I can define class in Scheme like this:
To make a JavaScript class with a public method I'd do something like: function
Say I have a Javascript class defined and instantiated like this: Demo = function()
I would like to ask, how can I define class inside another one. In
I can define default value in domain by this way : class ProcessingPriority {
I'd like to define a class type inside my namespace, but I can't think
I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public
Can we define multiple models in the Meta class part of a Form ?
Can I define style in CSS for input with attribute selectors and a class
I'm stuck. I'm trying to dynamically define a class method and I can't wrap

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.