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?

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

It is just an example: this not really "match" with a really case. I ask this because the tutorial does not explain it. Maybe is better change the case to become more understandable. I will test and see the if results
@Ricardo Again, I just wanted to warn you if you intended this code for production
Thank you :) It Works for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.