Horje
Private slots are new and can be created via Instance and static private fields Code Example
Private slots are new and can be created via Instance and static private fields
// ES2022
class InstPrivateClass {
  #privateField1 = 'private field 1'; // (A)
  #privateField2; // (B) required!
  static #staticPrivateField = 'hello';
  constructor(value) {
    this.#privateField2 = value; // (C)
  }
  /**
   * Private fields are not accessible outside the class body.
   */
  checkPrivateValues() {
    console.log(this.#privateField1); // output -> 'private field 1'
    console.log(this.#privateField2); // output -> 'constructor argument'

  }

  static #twice() {
    return this.#staticPrivateField + " " + this.#staticPrivateField;
  }

  static getResultTwice() {
    return this.#twice()
  }
}

const inst = new InstPrivateClass('constructor argument');
inst.checkPrivateValues();


console.log("inst", Object.keys(inst).length === 0) //output -> "inst", true
console.log(InstPrivateClass.getResultTwice()); // output -> "hello hello"
Source: dev.to




Javascript

Related
If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph? Code Example If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph? Code Example
nextjs query parameter Code Example nextjs query parameter Code Example
angular dynamic script loading Code Example angular dynamic script loading Code Example
connecting nodejs using mongoose Code Example connecting nodejs using mongoose Code Example
react native andri]oid ReferenceError: Can't find variable: Intl Code Example react native andri]oid ReferenceError: Can't find variable: Intl Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8