3 ms·
Here's a pattern I've been using for some time in ES6 JavaScript (on Node.js) : module.exports = class MyClass { // ... static init () {
by galaxyLogic 5y ago
Here's a pattern I've been using for some time in ES6 JavaScript (on Node.js) :
module.exports =
class MyClass
{ // ...
static init ()
{ // ... do something, like create and
// cache a Singleton etc.
return this;
}
} . init();
The static method init() is executed only once when the class is created and exported. You could add some check to it that causes an error if it gets called more than once.
Do static blocks allow me to do something more?