apply function in JavaScript

2019-06-20 16:07发布

问题:

I'm learning JavaScript and I'm currently trying to figure out why (in Spidermonkey)

[].concat.apply([1], [[2]])

returns the expected [1, 2], but

Array.concat.apply([1], [[2]])

returns [2] instead of [1, 2].

Could someone provide a good explanation?

回答1:

[].concat is Array.prototype.concat.

Array.concat is a Firefox-only static method that concatenates one or more arrays and ignores its this argument.