我正在尝试使用 Jasmine 来测试我的代码,但是代码在浏览器中工作,并且 Array.from() 在 Node 中工作,如下所示:
> t = [1, 2, 3]
[ 1, 2, 3 ]
> Array.from(t)
[ 1, 2, 3 ]
这是在 Firefox 中运行的代码:
var t = [1, 2, 3];
console.log(Array.from(t));
console.log(Array.from(baseObject.childNodes));
但是当我运行测试时我得到:
TypeError: undefined is not a function (evaluating 'Array.from(t)') in file:///path/to/my/project/bin/my_module.js (line 154) (1)
最佳答案
Array.from
已添加到 ECMAScript 标准第六版 (ES2015) 中。确保您使用足够新的 ECMAScript 版本进行测试。
关于javascript - Array.from 不适用于 jasmine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50126100/