How to define methods in class with JavaScript ES6

1 Answer

0 votes
class CTest {
  Method1() { return 3; }
  ['Method' + '2']() {} 
 
  static stMethod() { return 10; }
}
 
console.log(CTest.prototype.Method1.name); 
console.log(new CTest().Method1.name); 
 
const obj = new CTest();
console.log(obj.Method1());
 
console.log(CTest.prototype.Method2.name); 
 
console.log(CTest.stMethod.name); 
   
console.log(CTest.stMethod());
       
 
 
/*
run:
      
Method1
Method1
3
Method2
stMethod
10
 
*/

 



answered Mar 25, 2020 by avibootz
edited Mar 25, 2020 by avibootz

Related questions

1 answer 167 views
1 answer 215 views
1 answer 152 views
2 answers 299 views
2 answers 240 views
...