Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Inside Vs Static Methods

 class Person {
	   constructor(myName) {
	     this.name = myName;
		 console.log(this.getName());
	   }

	   getName() {
	     return this.name;
	   }

	   static getName2() {
	     return 'getName2 result';
	   }
	 }
	 
	 

/*getName can be access either inside the class as this.getName or any instance p of TestClass can access with p.getName()...getName2 However, can only be access via Person.getName2() instances do NOT have access*/
 
PREVIOUS NEXT
Tagged: #Inside #Vs #Static #Methods
ADD COMMENT
Topic
Name
5+2 =