Why you might want to create static class members?

Why you might want to create static class members?

Team Leader Asked on June 5, 2018 in JAVASCRIPT,   JQUERY.
Add Comment
1 Answer(s)

Because Static method calls are made directly on the class and are not callable on instances of the class. Static methods are often used to create utility functions.

 

Classes Static:

class StaticMethodCall {
constructor() {
console.log(StaticMethodCall.staticMethod());
// expected output: “static method has been called.”
}

static staticMethod() {
return ‘static method has been called.’;
}
}

new StaticMethodCall();

Senior Developer Answered on July 16, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.