我正在尝试使用库: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()参考吗?
js数学库欣赏的任何其他建议。
发布于 2016-02-20 18:12:19
new linearAlgebra().Matrix(...)被解释为
( new linearAlgebra() ).Matrix(...)由于JS的优先规则(详见here )。
将其括在括号中以得到您想要的内容:
new ( linearAlgebra().Matrix )(...)https://stackoverflow.com/questions/35526921
复制相似问题