在JavaScript中应用函数 [英] apply function in JavaScript

查看:111
本文介绍了在JavaScript中应用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习JavaScript,并且正在尝试弄清楚为什么(在 Spidermonkey 中)

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

返回期望的 [1,2] ,但是

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

返回 [2] 而不是 [1,2]



有人可以提供一个很好的解释吗?

[]。concat Array.prototype.concat



Array.concat 是一个仅限Firefox的静态方法,用于连接一个或多个数组并忽略其 this 参数。 p>

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?

解决方案

[].concat is Array.prototype.concat.

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

这篇关于在JavaScript中应用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆