Replies: 2 comments
-
I think I found it. Something like:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Instead of using A Here a very basic example: // define a Map interface as scope
const scope = {
has: (name) => name === 'dmg_taken' ? true : false,
get: (name) => name === 'dmg_taken' ? 42 : undefined,
keys: () => ['dmg_taken'],
set: (name, value) => { /* TODO: implement */ }
}
math.evaluate('3*dmg_taken', scope) // 126 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Background:
I made a poor decision many years ago when I started on a project, running a lot of math evaluations with a ton of variables using parser.set. Previously, it's worked fine to just calculate all variables before every evaluation and supplying them to
parser.set
. But now the variables I need and the time to calculate them has grown substantially. So I thought it'd be a better design to turn these variables into no-argument getter functions, so that they only need to be executed when they're actually used in an evaluation.The problem:
Now I have formulas that might look like
3*dmg_taken
, and if I want the dmg_taken variable to become a getter, I'd need to change my formula to3*dmg_taken()
. However, at this point there's thousands of formulas spread across the project, so going through and changing everything would take weeks.Basically, is there a way I can call a function without requiring the parentheses if one is encountered, supplying no arguments?
Beta Was this translation helpful? Give feedback.
All reactions