Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda