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

186
Visualizações
More elegant and secure solution to passing object path references

I've been reading SICP and one concept they teach is abstracting certain details away from the user. I'm trying to build a set of subfunctions that return object paths that can be passed as an argument in a higher order function. The problem I found was that most of the time javascript will resolve the object path to whatever value it's referencing before passing it to the higher order function. With some help I managed to cobble together this crude solution but I was hoping theres a better way.

let object = {
prop1: "sth",
prop2: "sthelse"
}
function getPath(whichProp) {
    return `object["${whichProp}"]`};

function deleteProp(aPath) {
    console.log(aPath) //prints object["prop1"]
    eval(`delete ${aPath}`);
    console.log(object) // {prop2: sthelse}
}

deleteProp(getPath("prop1"))

Is there some method of message passing that can be used here? Having the function resolve to a function calling it's argument with itself as that functions' argument. Hope that's coherent, thanks in advance.

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