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

153
Visualizações
Strict Mode. Extract internally defined variables out of a referenced function

I'm trying to find a way to "extract" all internally defined variables within a function passed to another function. This looks to be impossible, but something tells me that I haven't tried all possible solutions. I need to get a references to the callerFunction's internalVariable inside the tryReadInternalVarvalue

The code is simplified, but the similar code already works with the JavaScript array .findIndex-method - it doesn't care about scopes and the strict mode. In the code sample below, exactly in the tryReadInternalVarValue I need to find which value was used against my targetObj.title to match. I have control over my targetObj.

const tryReadInternalVarValue = function(functionRef) {
    const targetObj = {
        title: "World"
    };

    const isMatch = functionRef(targetObj);
    if (!isMatch) {
        throw Error(``);
    }

    // Here must go my code to "extract" all the functionRef internal variables
    // naive console.log(functionRef[["Scopes"]]["Closure"]["internalVariable"]) ==> "Hello"

    // Is there a way (like Reflection) to figure out which value 
    // was used against the targetObj.title to compare HERE?
    // How I would extract the "Hello" value out of the passed function's
    // internally declared variable in STRICT MODE?
    return isMatch;
}

const callerFunction = function() {
    const internalVariable = "Hello";
    const meCallingThisFunction = function (passingThisObject) {
        return passingThisObject.title === internalVariable;
    }

    return tryReadInternalVarValue(meCallingThisFunction)
}

console.log(callerFunction());

I tried:

  • arguments.caller - in strict mode it's not available
  • functionRef.call(new Proxy({}, {get(target, p, receiver) { console.log()}}), targetObj)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This looks to be impossible

…and it absolutely is. Closed-over variables are private, you cannot access them from outside.

about 4 years ago · Juan Pablo Isaza Relatório
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