How to call custom methods for script call?

Game_Interpreter.prototype.my_custom_func = function(formula) { return eval(formula);};Simple method. Intended use is to simply evaluate a formula.In Ruby, I would just say make a script call

my_custom_func("$game_party.members.length > 2")And it will return whatever the formula should return.However, in JS, eval's do not have context.

When the script call command goes and calls eval, it's done in global space.

I would need to do something like this if I don't modify the way script calls are handled.

Code:
this.my_custom_func( ... )
Is there another way to call custom methods for script calls without forcing users to write "this"?
Don't know if function binding can help here 🙂
If you use strict mode, eval should be unable to introduce new variables to the global space.

Otherwise you could create a new function, like this:

Code:
Game_Interpreter.prototype.my_custom_func = function(formula) {   return new Function("return " + formula + ";")();};
If you use strict mode, eval should be unable to introduce new variables to the global space.

Otherwise you could create a new function, like this:

Game_Interpreter.prototype.my_custom_func = function(formula) { return new Function("return " + formula + ";")();};
Hmm, the issue I'm having now is that the game interpreter doesn't even recognize my_custom_func because it's checking the global space for a function called "my_custom_func", rather than checking its own context.

I could always just define my_custom_func globally though.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-call-custom-methods-for-script-call.48642/