Skip to content

Commit 9b8e324

Browse files
committed
docs: document using methods in the parser (fixes #3462)
1 parent f404dab commit 9b8e324

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

docs/expressions/syntax.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Expression syntax
22

3-
This page describes the syntax of expression parser of math.js. It describes
3+
This page describes the syntax of the expression parser of math.js. It describes
44
how to work with the available data types, functions, operators, variables,
55
and more.
66

@@ -249,6 +249,26 @@ Note that math.js embodies a preference for the operator forms, in that calling
249249
`simplify` (see [Algebra](./algebra.md)) converts any instances of the function
250250
form into the corresponding operator.
251251

252+
## Methods
253+
254+
Some data types have methods which can be used in the parser using the dot notation, for example:
255+
256+
```js
257+
const parser = math.parser()
258+
259+
parser.evaluate('a = 1 m') // Unit 1 m
260+
parser.evaluate('a.toNumber("mm")') // 1000
261+
```
262+
263+
Or a method on a Matrix or Array:
264+
265+
```js
266+
const parser = math.parser()
267+
268+
parser.evaluate('M = [4, 9, 25]') // Matrix [4, 9, 25]
269+
parser.evaluate('M.map(sqrt)') // Matrix [2, 3, 5]
270+
```
271+
252272
## Map and forEach
253273

254274
The `map` and `forEach` functions can be used to apply a callback function to each element of an array or matrix.

0 commit comments

Comments
 (0)