I have following javaScript \"class\":
A = (function() {
a = function() { eval(...) };
A.prototype.b = function(arg1, arg2) { /* do something... */};
}
What worked for me was using Function
constructor and calling it in specified context:
var o = {
x: 10
}
(new Function(`console.log(this.x)`)).call(o);
This somehow doesn't work in browser's console but works elsewhere.
You can use my library https://github.com/marverix/meval .
const meval = require('meval');
console.log(
meval('item.a + item.b * 5', { item: { a: 2, b: 3 } })
);
// outputs: 17