Why is it that individuals with [1].a are unable to utilize the properties from the User class?

Why is it that people are unable to access properties directly from the User class, but instead need to access them nested through proto ?!

class User {
        constructor(name, age) {
            this.name = name;
            this.age = age;
        }

        static a = 12;
    }

    class User2 extends User {}

    let people = [
        new User2('Vasia', 20),
        new User2('Peter', 19),
        new User2('Misha', 21),
    ]



    console.dir(User2.a) // 12
    console.dir(people[1].a) // ?????

Answer №1

Static attributes are properties that can be found on the Class objects, rather than on individual instances of the class.

They are typically used to store static methods.

According to MDN:

The static keyword is used to define a static method for a class. These methods are not called on instances of the class but are instead called directly on the class itself. These static methods are commonly used for utility functions like object creation or cloning.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A useful method to generate dynamic and random interval values for each loop of setInterval in NodeJs

I am trying to implement a feature where a function in nodeJS triggers another function at random intervals within a specified range. Each time the loop occurs, I want the interval value to be different and randomly generated between 3 and 5 seconds. bot ...

Trigger Audio Playback in Javascript

Currently working on a webpage with an embedded audio file using the HTML audio tag. The viewer controls the audio playback, but I'm looking to add a button (either in HTML or Javascript) that, when clicked, will start playing the audio from a specifi ...

Verify whether a string includes any of the elements within an array

Imagine I have a string: const subject = "This process is flawless" and an array: const matchArray = ["process","procedure","job"] If subject contains any keyword from matchArray, I want to do the following: if (su ...

Utilizing ReactJS alongside either jQuery or vanilla JavaScript

As a newcomer to ReactJS, I find myself struggling with using it for more complex tasks. While I grasp the fundamentals, my mind often defaults to jQuery or plain JavaScript when attempting more advanced projects. For example, if I were to create a web a ...

Implementing meta tags in React.js

I am attempting to incorporate dynamic meta-tags on each page of my website. However, despite my efforts, I cannot seem to locate the meta-tags in the page's source code. Do I need to make adjustments in public/index.html, considering that I am not ut ...

Open the JSON file and showcase its contents using Angular

I am attempting to read a JSON file and populate a table with the values. I've experimented with this.http.get('./data/file.json') .map(response => response.json()) .subscribe(result => this.results =result, function(error) ...

Numerous images with clickable features

Currently, I am in the process of designing a screen that will showcase around 50 toggle buttons to be displayed on a monitor within a building. My goal is to incorporate a variety of images as toggles to ensure they are easily visible and identifiable. I ...

Keep fancybox items in their designated spot

When the window is opened at full size, everything looks fine. However, when you resize the window horizontally, the thumbnails shift and disappear. I want them to remain fixed in their position like the large pop-up image so that users can still see them ...

Tracing a path with a snapping motion using my thumb

Before we begin, let's take a look at the example below. The functionality of this component should mimic that of an input type range. However, I am facing some challenges in calculating the step value and snapping the thumb onto the trail based on t ...

Exploring the Functionality of Callbacks in Implementing Methods

I am curious about how we can call res.render from within a callback function. function retrieveUsers(callback){ fs.readFile('data.json', 'utf8', (err, data) => { if (err) return callback(err); const users = JSON.parse(data ...

Executing server-side method with jQuery in .Net 1.1

Currently, I am utilizing .net1.1 and attempting to invoke a server-side method using jQuery upon clicking the browser's Close button. However, my code does not seem to be functioning correctly. I have provided my code below for reference. Can anyone ...

Exploring ways to retrieve nested values from JSON data using the Instagram API and Javascript

Trying to modify the script found at https://github.com/bigflannel/bigflannel-Instafeed in order to access Instagram photos on a website. Unfortunately, the script does not currently support displaying photo comments. I attempted to make modifications that ...

Exploring the World of Dates with Angular JS

let discoverDate = new Date('08-24-2015'); let occurDate = new Date('06-07-2018'); let discover = $filter("date")(discoverDate, "MM/dd/yyyy"); let occur = $filter("date")(occurDate, "MM/dd/yyyy"); console.log(discover); console.log(oc ...

The 'Bfrip' button is missing from the DOM

Having some issues with displaying table content using DataTables. Everything seems to be working smoothly except for the Buttons, which are not appearing as expected. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.1 ...

Example of jQuery UI tabs - each new tab opens with a unique script assigned

Here is a jQuery tabs script that you can check out: http://jqueryui.com/demos/tabs/#manipulation var $tabs = $( "#tabs").tabs({ tabTemplate: "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ...

Observing an element within AngularJS

Struggling to watch an object in AngularJs 2. In a directive, I have an object like this: scope.timelineFilter = {hasCapacity: true, onlyActivated: true, companyIdList: []}; I use 2 JQuery functions to change values of the object (adding a third soon) ...

How to dynamically disable a dropdown based on the selection of another dropdown using AngularJS

This project has been more challenging than I anticipated. I thought it would be a simple task to accomplish. Currently, I am developing a basic form with an input text field and two dropdown boxes. These dropdown boxes represent different types of contra ...

Utilizing JavaScript to send various arrays to a .NET web service

Hey everyone, I'm currently facing an issue with posting multiple arrays to a .net web service and here is the signature of the web service. <WebMethod()> _ Public Function Lib_Processor(ByVal w_vendor As String(), _ ...

Using JavaScript regular expressions for email validation criteria

Hey there, I am struggling with Regular Expressions, especially when it comes to client side validation for a specific field. Can you please help me come up with a Regular Expression that would verify if an email address is valid based on these criteria: ...

I need to search through a tree structure in typescript based on a specific value without encountering a maximum stack call exceeded error

How can I perform a value-based search on a complex tree structure in TypeScript without encountering the maximum stack call exceeded error? I am attempting to navigate through an expandable tree using TypeScript, and I will provide the code snippet below ...