我正在尝试使用库:https://github.com/hiddentao/linear-algebra
文档说明要使用:
Include dist/linear-algebra.js script into your HTML.
In the browser the library is exposed via the linearAlgebra() function.
但使用代码:
<script src="linear-algebra.js"></script>
<!-- https://github.com/hiddentao/linear-algebra
-->
<script>
var m = new linearAlgebra().Matrix([ [1, 2, 3], [4, 5, 6] ]);
console.log( m.rows ); // 2
console.log( m.cols ); // 3
console.log( m.data ); // [ [1, 2, 3], [4, 5, 6] ]
</script>
导致 Chrome 错误:
Uncaught TypeError: Cannot read property 'rows' of undefined
我没有以正确的方式使用该库,应该只能使用linearAlgebra()
ref?
任何其他推荐的 js 数学库表示赞赏。
最佳答案
new linearAlgebra().Matrix(...)
被解释为
( new linearAlgebra() ).Matrix(...)
由于 JS 优先规则(请参阅 here 了解详细信息)。
将其括在括号中以获得您想要的内容:
new ( linearAlgebra().Matrix )(...)
关于javascript - 无法使用库 https ://github. com/hiddentao/linear-algebra 运行简单示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35526921/