Priv
and Pub
is my way of simulating Private and Public;()()
so it works the way I want it to. I want to be able to type Priv.whateverProp
()
, then the completions display apply, bind, call etc
.getInstance()()
.completions**
again to access the instance properties, but when I run the program, it says SingletonFinder().getInstance() is not a function
Priv().whaterverProp
instead of Priv.whateverProp
for the rest of the code, which I don't want.let Priv = SingletonFinder().getInstance()()
?function GetFinder(){
let Pub = {}
let Priv = SingletonFinder().getInstance()()
// the rest of the code...
}
function SingletonFinder() {
let Priv = {}
let Pub = {}
/** @type {Class_Finder} */
Priv.instance = null;
Priv.createInstance = function () {
return Class_Finder
}
Pub.getInstance = function () {
if(!Priv.instance) {
Priv.instance = Priv.createInstance()
}
return Priv.instance
};
return Pub
}
function Class_Finder() {
// properties
}
Years later, after reviewing this project, I can conclude that:
SingletonFinder().getInstance()()
is due to 2 factors: a) you can access the returning value's properties and methods, if they exist, immediatly after calling a function; b) getInstance
's returning value is the Class_Finder
function, so in order to access the returning value of Class_Finder
, one more pair of parenthesis can be written right after the first one;The following code exemplifies why ()()
is necessary to output 'true':
const obj = {};
const fn = ()=>{return true}
obj.method = ()=>{return fn}
console.log(obj.method) //output: function
console.log(obj.method()) //output: function
console.log(obj.method()()) //output: true
Finally, it was all for fun! I've never been a pro coder and was just being a total beginner. Patterns fascinated me at the time as much as experimenting with coding and browsing the communities online.