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.