如何不印字或添加参数的对象开始在JavaScript中 [英] How to unshift or add to the beginning of arguments object in JavaScript
问题描述
我刚刚学到的<一个href=\"http://stackoverflow.com/questions/19903841/removing-an-argument-from-arguments-in-javascript\">convention对于突然离开的参数的第一个元素
阵列(我还了解到实际上是一个对象
) 。现在我需要做的是相反的。我需要使用不印字
操作的值增加的参数年初
阵列(或对象
的演技就像一个数组)。这可能吗?我想:
Array.prototype.unshift.apply('你好',参数);
这对参数没有影响
任何责任。
-
使用
.CALL()
而不是。适用()
调用的unshift()
-
设置
参数
为)的本
值的unshift( -
设置
'你好'
作为参数传递给的unshift()
Array.prototype.unshift.call(参数,'你好');
由于@lonesomeday指出的那样,你可以使用。适用()
而不是 .CALL()
,但你需要传递一个数组类参数作为第二个参数。所以你的情况,你需要换行'你好'
在数组中。
I've just learned the convention for popping off the first element of the arguments
array (which I also learned is actually an Object
). Now I need to do the opposite. I need to use an unshift
operation to add a value to the beginning of the arguments
array (or Object
acting like an array). Is this possible? I tried:
Array.prototype.unshift.apply('hello', arguments);
That had no effect on arguments
whatsoever.
use
.call()
instead of.apply()
to invokeunshift()
set
arguments
as thethis
value ofunshift()
set
'hello'
as the argument tounshift()
Array.prototype.unshift.call(arguments, 'hello');
As @lonesomeday pointed out, you can use .apply()
instead of .call()
, but you need to pass an array-like argument as the second argument. So in your case, you'd need to wrap 'hello'
in an Array.
这篇关于如何不印字或添加参数的对象开始在JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!