0

I'm starting using the new way of OO in javascript by following this tutorial. This new way of OO of javascript follows the ES6 specification.

Follows a sample of my code:

class SomeClass{

        static SomeFunction(data){
            this.data = data;
        }

}

What I want is to make the variable this.data static.

Is any way that I could do that?

Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130

1 Answers1

3

Because the new class keyword is just syntatic sugar you can do

SomeClass.staticVariableName = value;

Put this outside of the class, if you put it in the constructor, then it will only be initialized when you create at least 1 instance.

Side note: if this is a client side code, then I just want to warn you that you shouldn't authenticate people client side, because it's terribly insecure.

Ricardo Rocha
  • 14,612
  • 20
  • 74
  • 130
Bálint
  • 4,009
  • 2
  • 16
  • 27