首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用库https://github.com/hiddentao/linear-algebra运行简单示例

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

Stack Overflow用户
提问于 2016-02-20 17:56:42
回答 1查看 58关注 0票数 0

我正在尝试使用库:https://github.com/hiddentao/linear-algebra

“文件”规定使用:

代码语言:javascript
复制
Include dist/linear-algebra.js script into your HTML.

In the browser the library is exposed via the linearAlgebra() function.

但是使用代码:

代码语言:javascript
复制
<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错误:

代码语言:javascript
复制
Uncaught TypeError: Cannot read property 'rows' of undefined

我不是以正确的方式使用库的,应该只是能够使用linearAlgebra()参考吗?

js数学库欣赏的任何其他建议。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-20 18:12:19

代码语言:javascript
复制
new linearAlgebra().Matrix(...)

被解释为

代码语言:javascript
复制
( new linearAlgebra() ).Matrix(...)

由于JS的优先规则(详见here )。

将其括在括号中以得到您想要的内容:

代码语言:javascript
复制
new ( linearAlgebra().Matrix )(...)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35526921

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档