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

180
Visualizações
How can I call unscoped functions in eval without using "this"

This works:

import isValidDocument from './isValidDocument'

class Test {
  constructor() {
    Object.assign(this, { isValidDocument})
  }

  execute(person) {
    const evalResult = eval('this.isValidDocument(person)')
    console.log("Eval Result:", evalResult)
  }
}

but this doesn't:

// ...
execute(person) {
  const evalResult = eval('isValidDocument(person)')
  console.log("Eval Result:", evalResult)
}
// ...

Basically, i want to be able to call the functions without using the this keyword.

How can I achieve that?


If you want context

I have rules (js expressions) stored in a database and i need it to execute them dinamically, the functions are fixed but the expressions can change.

Expression example: isValidDocument(person) && person.age > 18

The user will be able to change the expressions.

Yeah, i know about the security issue and i also accept suggestions to isolate the env. Currently, the expressions are made using blocks on the frontend and then the backend converts them to actual javascript statements, but the plan is to allow the user to create his own expressions directly.

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