【发布时间】:2019-08-23 13:24:26
【问题描述】:
我讨厌我问这个问题,但我浏览过每一个标记为 mathjs 或 math.js 的堆栈溢出帖子,以及一大堆带有“x 不是函数”的帖子,但没有一个相关或有帮助。这是我在 Google Chrome 中获得的完整堆栈跟踪:
Uncaught TypeError: v is not a function
at p (math.js:1741)
at typed (eval at p (math.js:1740), <anonymous>:15:16)
at Object.r [as factory] (math.js:15041)
at t (math.js:232)
at Object.n [as factory] (math.js:30335)
at t (math.js:232)
at Object.n [as factory] (math.js:30256)
at t (math.js:232)
at Object.n [as factory] (math.js:29710)
at t (math.js:232)
请注意,没有一个错误指向我的代码,如果我尝试在控制台中调用任何数学方法,我会得到完全相同的错误。
我使用 p5.js 只是为了为我的网站制作一些交互性的东西,我需要 math.js 的表达式解析功能。
这是我的 html 文件:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2D plotter</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/3.3.0/math.min.js"></script> <!-- here's where I load math.js from a cdn -->
<!-- PLEASE NO CHANGES BELOW THIS LINE (UNTIL I SAY SO) -->
<script language="javascript" type="text/javascript" src="libraries/p5.min.js"></script>
<script language="javascript" type="text/javascript" src="Function.js"></script>
<script language="javascript" type="text/javascript" src="Plot.js"></script>
<script language="javascript" type="text/javascript" src="WebsitePlotter2D.js"></script>
<!-- OK, YOU CAN MAKE CHANGES BELOW THIS LINE AGAIN -->
<!-- This line removes any default padding and style.
You might only need one of these values set. -->
<style> body { padding: 0; margin: 0; } </style>
</head>
<body>
</body>
</html>
当处理编辑器生成原始 html 文件时,“请不要更改”行就在那里,我没有弄乱它。这里是调用 math.js 库的代码,尽管在这一点上我确信它是无关紧要的:
draw() {
let lastPoint = null;
let nx, ny, y;
const parser = math.parser();
stroke(this.lineColor);
strokeWeight(this.lineWeight);
for (let xv=this.plot.xStart; xv<this.plot.xStop; xv+=this.step) {
parser.set('x', xv);
y = parser.evaluate(this.func);
ny = this.plot.scalePixelY(y);
nx = this.plot.scalePixelX(xv);
if (lastPoint !== null && 4) {
line(lastPoint.xVal, lastPoint.yVal, nx, ny);
}
lastPoint = {xVal: nx, yVal: ny,};
}
}
此外,如果我转到追溯中引用的 math.js 中的行,则没有方法调用,甚至没有 v 的变量名,所以我不确定发生了什么。感谢任何帮助,我想把这个愚蠢的错误抛在脑后。
【问题讨论】:
标签: mathjs math.js javascript p5.js mathjs math.js