如果您在此页面上运行此javascript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from 得到以下结果:
console.log(Array.from([1, 2, 3], x => x + x));
// expected output: Array [2, 4, 6]
> Array [2, 4, 6]
如果您在此页面上的Chrome控制台中运行相同的代码(https://portal.fellowshipone.com/),我会得到以下结果:
console.log(Array.from([1, 2, 3], x => x + x));
// expected output: Array [2, 4, 6]
VM2786:1 (3) [1, 2, 3]
为什么会这样?
答案 0 :(得分:2)
您所指的页面正在使用Prototype库中的Array.from
。尝试将Array.from
输入控制台,您将看到此函数在外部库中声明,该库将覆盖native implementation。