I am essentially creating singleton classes with javascript, which look like this
const ClassExample = function(input){
const _myInput= input;
this.myFunc = function(){
return _myInput;
}
}
I can call the above like this
const myClass = new ClassExample("hello");
console.log(myClass.myFunc());
How can I add another function which I can call without initiating the ‘class’
This is what I’d like to do
const ClassExample = function(input){
const _myInput= input;
this.myFunc = function(){
return _myInput;
}
this.myStatic = function(){
return "my static";
}
//static myStatic = function().... does not work, probably because it's syntax magic that works with the type class
}
console.log(ClassExample.myStatic());
Is what I want to do achievable like this?
1