javascript - Define a const in class constructor (ES6) -


this question has answer here:

is there way can define const in constructor of class?

i tried this:

class foo {     constructor () {         const bar = 42;     }      getbar = () => {         return this.bar;     } } 

but

var = new foo(); console.log ( a.getbar() ); 

returns undefined.

you use static read-only properties declare constant values scoped class.

class foo {     static bar() {         return 42;     } }  console.log(foo.bar); // print 42. foo.bar = 43; // triggers error 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -