expr-eval
expr-eval copied to clipboard
Improve documentation
Make sure the documentation is up to date, and covers everything it needs to.
How do I add own javascript function? expr-eval always return Uncaught error: undefined variable xyz
@layanto You'll need to create an instance of the Parser class, then you'll be able to add your functions to the functions property.
var parser = new Parser();
parser.functions.xyz = function (x, y) { return x * y; };
parser.parse('xyz(4, 3)').evaluate(); // 12
You can also delete and override the built-in functions the same way.
Note that you won't be able to use the "static" Parser.parse() and Parser.evaluate() functions because they use their own instance of the class that won't know about your custom functions.
Trying to add my own function to parser using typescript, but functions is missing from the typings file.