javascript - apply第二个参数不是应该是个数组吗?对象也行吗?

查看:94
本文介绍了javascript - apply第二个参数不是应该是个数组吗?对象也行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

如图

解决方案

Syntax
fun.apply(thisArg, [argsArray])

Parameters

  • thisArg

The value of this provided for the call to fun. Note that this may not be the actual value seen by the method: if the method is a function in non-strict mode code, null and undefined will be replaced with the global object, and primitive values will be boxed.

  • argsArray

An array-like object, specifying the arguments with which fun should be called, or null or undefined if no arguments should be provided to the function. Starting with ECMAScript 5 these arguments can be a generic array-like object instead of an array. See below for browser compatibility information.

从es5开始支持array-like的object啦,所有array-like就是有length属性,有index作为key的object啦。
你这个object正巧就有length属性,不过没有键值对,所以遍历出5个undefined

这篇关于javascript - apply第二个参数不是应该是个数组吗?对象也行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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