Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
Does javascript singleton require double parentheses?
  • I created a Singleton-like function for a Google Sheet of mine;
  • Priv and Pub is my way of simulating Private and Public;
  • When I assign its instance to a variable, I need to type ()() so it works the way I want it to. I want to be able to type Priv.whateverProp
  • I've tried double parentheses in other places inside the Singleton function, but when I accomplish getting to use only one (), then the completions display apply, bind, call etc.
  • Then I have to getInstance()().completions** again to access the instance properties, but when I run the program, it says SingletonFinder().getInstance() is not a function
  • So I have to leave getInstance() with its single parentheses and type Priv().whaterverProp instead of Priv.whateverProp for the rest of the code, which I don't want.
  • Why do I have to type it this way 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
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!