gpt4 book ai didi

javascript - 为什么 Array 中的函数不能在 'arguments' 上工作?

转载 作者:行者123 更新时间:2023-11-28 15:42:49 25 4
gpt4 key购买 nike

为什么我们不能直接在参数上调用数组中的函数?

function f(){
var x = Array.prototype.slice.call(arguments,1);
//var x = arguments.slice(1); **error**
alert(x);
}

f(1,2,3);

更新:如果 arguments 不是数组对象,那么 Array.prototype.slice 函数如何在非数组对象上工作?

最佳答案

因为,尽管 arguments 对象具有一些类似数组的特性,但它并不是一个数组。

defined独立于且不引用 Array objects .

关于javascript - 为什么 Array 中的函数不能在 'arguments' 上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23289373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com