函数 resolve #

resolve(expr, scope) 将变量节点替换为其作用域中的值

Syntax #

math.resolve(expr, scope)

Parameters #

Parameter Type Description
node Node | Node[] 要简化的表达式树(或树)
scope Object 指定要解析的变量的作用域

Returns #

Type Description
Node | Node[] 返回 node,其中变量被递归替换。

Throws #

Type Description
ReferenceError 如果在 scope 中的变量之间存在循环依赖,则无法解析,并抛出 ReferenceError。

Examples #

math.resolve('x + y', {x:1, y:2})           // Node '1 + 2'
math.resolve(math.parse('x+y'), {x:1, y:2}) // Node '1 + 2'
math.simplify('x+y', {x:2, y: math.parse('x+x')}).toString() // "6"

另请参阅 #

simplify, evaluate

Fork me on GitHub