Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Private properties in JavaScript ES6 classes

class Something {
  #property;

  constructor(){
    this.#property = "test";
  }

  #privateMethod() {
    return 'hello world';
  }

  getPrivateMessage() {
      return this.#property;
  }
}

const instance = new Something();
console.log(instance.property); //=> undefined
console.log(instance.privateMethod); //=> undefined
console.log(instance.getPrivateMessage()); //=> test
Comment

js es6 class private method

class MyClass
{
  	// Prepend hash to make it private. Browser support at:
  	//	https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields#browser_compatibility
    // Dynamic access (ie: this.#[fieldName]) is disallowed by design.
  	#myPrivateMethod() {
    	// do private things
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: even digit sum java 
Java :: kotlin enable and disable parents view children 
Java :: how to check if a char is a letter java 
Java :: spring security enable global cors 
Java :: Triangle Pattern In Java 
Java :: how to check if a string is empty or null in Android Studio 
Java :: sorting hashmap by key in java 8 
Java :: java string swap two characters 
Java :: write json string to file in java 
Java :: get first character of string java 
Java :: java import joptionpane 
Java :: what is an error in java 
Java :: java sout two dimensional array 
Java :: how to check my java heap space size 
Java :: spring boot mongodb update subdocument 
Java :: java substring 
Java :: how to convert int to integer in java 
Java :: array to arraylist java 
Java :: java string to double 
Java :: change javahome cmd 
Java :: spinner event in android 
Java :: how to resize image in android programmatically 
Java :: sorting the characters of a string in java 
Java :: java loop through object 
Java :: pass list to intent in android java 
Java :: hashmap iteration 
Java :: how to do the maximum of three numbers in java 
Java :: java tomorrow date 
Java :: how to import math lib in java 
Java :: upload byte array to oss 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =