Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

4. You want to print the incremental count each time you instantiate a object using new in JS

class Key {
    // The static property
    static lastKey = 0;
    
    // The instance property using the class fields proposal syntax
    // Note I didn't initialize it with 1, that's a bit misleading.
    key;
    
    constructor() {
        // Increment and assign
        this.key = ++Key.lastKey;
    }

    print_key() {
        console.log(this.key)
    }
}

const key1 = new Key();
const key2 = new Key();
const key3 = new Key();

key1.print_key();
key2.print_key();
key3.print_key();
Comment

PREVIOUS NEXT
Code Example
Javascript :: JS glob to regex 
Javascript :: simple javascript router 
Javascript :: in object transform translate property concat with rotate value angular 7 
Javascript :: how to access match object in class component 
Javascript :: tableau javascript 
Javascript :: imasu ka meaning in japanese 
Javascript :: create javascript array from datalist dynamically 
Javascript :: jquery automatically click message alert 
Javascript :: javascript picture delete after time 
Javascript :: npm react router 6.0.0-alpha.2 
Javascript :: send props from one component to another on button click 
Javascript :: mat slider in a reactve form 
Javascript :: onclick start and stop the count react 
Javascript :: The value associated with each key will be an array consisting of all the elements that resulted in that return value when passed into the callback. 
Javascript :: js background color to null 
Javascript :: getElementbyhref 
Javascript :: how to find the current date and time of a city in js 
Javascript :: VUE DECLARE COMPONENT IN MAIN.JS 
Javascript :: class in side class in jss 
Javascript :: why setjavascriptenabled will true 
Javascript :: rust zola vuejs 
Javascript :: in javascript advertising on website only for 5 seconds 
Javascript :: media query for mobile in react file 
Javascript :: how to find dublicates in string 
Javascript :: tips and tricks for javascript 
Javascript :: selectize get instance id from onchange 
Javascript :: rails json exclude nested attribute 
Javascript :: 4.1.1. More On Strings¶ 
Javascript :: ng serve -- port 5200 
Javascript :: javascript add navbar link 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =