为什么不Array.push.apply工作? [英] Why doesn't Array.push.apply work?

查看:144
本文介绍了为什么不Array.push.apply工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如上所述这里,一个快速的方法来追加数组b中的javascript数组是 a.push.apply(A,b)

As described here, a quick way to append array b to array a in javascript is a.push.apply(a, b).

您会注意到对象在被使用了两次。真的,我们只是想功能, b.push.apply(A,B)完成同样的事情 - 第一个参数适用耗材这个的应用功能

You'll note that the object a is used twice. Really we just want the push function, and b.push.apply(a, b) accomplishes exactly the same thing -- the first argument of apply supplies the this for the applied function.

我想这可能更有意义,直接使用数组对象的方法: Array.push.apply(A,B)。但是,这并不工作!

I thought it might make more sense to directly use the methods of the Array object: Array.push.apply(a, b). But this doesn't work!

我很好奇,为什么没有,如果有一个更好的方式来实现我的目标。 (运用功能,而不需要调用特定阵列的两倍。)

I'm curious why not, and if there's a better way to accomplish my goal. (Applying the push function without needing to invoke a specific array twice.)

推荐答案

这是<一个href=\"https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/push\"><$c$c>Array.prototype.push,没有的Array.push

这篇关于为什么不Array.push.apply工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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