0

I'm looking for a way to declare a constant in a javascript class. I thought it may be something like that, but no :

class myClass {

const MY_CONSTANT = 1;

constructor() {
    ...
    }

The goal is to use thoses constant from other methods in the class.

   myMethod (add) {
   let x = add + MY_CONSTANT;
   ...
}

Any idea of the correct implementation ? Thanks

Keiro Dev
  • 1
  • 1
  • Do you want a constant static value (`myClass.MY_CONSTANT`) or a constant on each instance (`var o = new myClass(); o.MY_CONSTANT`)? – Mike Cluck Jul 26 '16 at 21:01
  • constant static value. But i need to access it from other methods inside the class itself – Keiro Dev Jul 26 '16 at 21:17
  • "access it from inside the class itself" What do you mean? By doing `this.MY_CONSTANT` or `myClass.MY_CONSTANT`? – Mike Cluck Jul 26 '16 at 21:19
  • Sorry, i just edited my previous comment. I mean from other methods of the class. I also edited my question for better understanding. – Keiro Dev Jul 26 '16 at 21:21

0 Answers0