Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么调用数组切片方法时使用";打电话;?_Javascript - Fatal编程技术网

Javascript 为什么调用数组切片方法时使用";打电话;?

Javascript 为什么调用数组切片方法时使用";打电话;?,javascript,Javascript,如图所示 在本例中,为什么将其编码为 args = Array.prototype.slice.call(arguments) 我可以吗 args = arguments.slice(); 我只是想了解使用call 还有其他一些场景,我们将不得不使用Array.prototype.slice.call(arguments)?arguments是类似于数组的对象,而不是数组。因此,它没有slice方法。您需要从数组获取切片实现,并将其上下文设置为参数。这将返回实际的数组,这是此操作的全部要点。

如图所示

在本例中,为什么将其编码为

args = Array.prototype.slice.call(arguments)
我可以吗

args = arguments.slice();
我只是想了解使用
call


还有其他一些场景,我们将不得不使用
Array.prototype.slice.call(arguments)

arguments
是类似于数组的对象,而不是
数组。因此,它没有
slice
方法。您需要从
数组
获取
切片
实现,并将其
上下文设置为
参数
。这将返回实际的
数组
,这是此操作的全部要点。

参数
不是数组:

function a(){console.log(typeof(arguments)) }
所以这个
a(123)
将产生
对象

因此,我们借用了处理类似数组的对象的方法,对对象进行切片,就好像它是真数组一样

可通过
call
apply
进行借用

apply
将参数作为数组发送(记住:
a
用于
array
)-而
call
将参数作为逗号分隔的值发送。

为什么不试着调用
arguments.slice()
…@deceze he:)我非常确定
参数
是数组!
function a(){console.log(typeof(arguments)) }