silentmatt / expr-eval

Mathematical expression evaluator in JavaScript
http://silentmatt.com/javascript-expression-evaluator/
MIT License
1.19k stars 239 forks source link

Uncaught Error: 2 is not a function #183

Closed kyleplo closed 5 years ago

kyleplo commented 5 years ago

Here is my code:

var Parser = exprEval.Parser;
var parser = new Parser();
var expr = parser.parse("m(2 - 7) + m(2m)");
expr.evaluate({m: 2});

I would expect it to return -2, but instead there is an error.

silentmatt commented 5 years ago

The library doesn't support implicit multiplication like that. It's something I'd like to add in the future, but I don't have a definite timeline. For now, you have to use the * operator, so your expression would need to be m*(2 - 7) + m*(2*m).

The m(2m) part actually only parses because of a bug that makes the parser more forgiving than it should be, and is equivalent to m(2, m). I'll need to fix that at some point.

kyleplo commented 5 years ago

Ok, thanks