【问题标题】:Not able to use Array.from无法使用 Array.from
【发布时间】:2022-01-12 10:30:02
【问题描述】:

我使用的平台仅支持 ECMAScript 5,因此我的 JavaScript 代码必须在该限制内工作。 Randomize 只是我写的一个辅助函数。此代码 sn-p 在不支持 ecmascript 5 版本的环境中完美运行,但在 ecmascript 5 环境中不起作用。函数 Array.find 在 ecmascript 5 中不存在。如何使它在 Ecmascript5 中工作?

提前致谢!

这是代码:

Array.from(crypto.getRandomValues(new Uint32Array(16))).map(randomize).join(‘’) 

【问题讨论】:

标签: javascript arrays ecmascript-5


【解决方案1】:

由于你不能使用函数,我想你可以重写一段函数代码,可以帮助你达到同样的条件。 这是我从其他开发人员那里得到的私有方法:

function arrayFrom (){
         let args = Array.prototype.slice.call(arguments);
         return args
};

arrayFrom(1,2,3)// printf: [1,2,3]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 2021-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多