javascript - 无法使用库 https ://github. com/hiddentao/linear-algebra 运行简单示例

标签 javascript linear-algebra

我正在尝试使用库: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/

相关文章:

python - 为什么 scipy.sparse.linalg.eigsh 给出错误的答案?

javascript - 快速了解 js 中的静态局部变量

javascript - 提交按钮无需点击即可调用函数

javascript - 如何将 html 转换为 draftjs?

c++ - 在 GPU 上计算特征值和特征向量的性能不佳

c# - 获取哪些值使数组中给定数字的总和的算法

javascript - 删除 Angular View 属性中的空间

javascript - 纯JS中的函数回调

C++ 逆矩阵

performance - Julia 的特征分解比 Mathematica 慢 5 倍?