当前位置:网站首页>Simple understanding of arguments in JS
Simple understanding of arguments in JS
2022-04-23 09:22:00 【Small white egg tart】
stay js Each function in has a built-in object ,arguments, It can replace any formal parameter , For example, without knowing the number of parameters .
arguments Is a special object , His attribute names are in the order of the parameters passed in , have access to arguments[i],i=0,1,2,3... And he has length attribute , Store the number of currently passed in parameters , You can think of it as a class array object , But not an array . As can be seen from the following procedure .
Three formal parameters were passed in , Namely 1,2,3, Separated by commas , Then we printed it arguments The type of object, And then use for Loop traverses three formal parameters .
And pay attention to fn(1,2,3) and fn([1,2,3]) The difference between
function fn() {
console.log(arguments);
console.log(typeof arguments);
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
}
fn(1, 2, 3);
Each comma is used to represent a formal parameter ,fn([1,2,3]) Indicates that what is passed in is a formal parameter , therefore arguments.length=1, Only arguments[0]=[1,2,3] Indicates that this array is a formal parameter , therefore arguments[1] for undefined.
function fn() {
console.log(arguments);
console.log(typeof arguments);
for (var i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
console.log(arguments[1]);
console.log(arguments.length);
}
// fn(1, 2, 3);
var a = [4, 5, 6];
console.log(a.length);
fn(a);
版权声明
本文为[Small white egg tart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624114450.html
边栏推荐
猜你喜欢
Buuctf [actf2020 freshman competition] include1
小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab
Using sqlmap injection to obtain the account and password of the website administrator
MySQL小練習(僅適合初學者,非初學者勿進)
AQS & reentrantlock implementation principle
A must see wechat applet development guide 1 - basic knowledge
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
[58] length of the last word [leetcode]
《數字電子技術基礎》3.1 門電路概述、3.2 半導體二極管門電路
npm ERR! network
随机推荐
Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
Kettle experiment conversion case
npm ERR! network
On array replication
小程序报错 :should have url attribute when using navigateTo, redirectTo or switchTab
Installation of data cleaning ETL tool kettle
kettle实验
GoLand debug go use - white record
Data visualization: use Excel to make radar chart
#yyds干货盘点#ubuntu18.0.4安装mysql并解决ERROR 1698: Access denied for user ''root''@''localhost''
Applet error: should have URL attribute when using navigateto, redirectto or switchtab
[reading notes] Chapter 5 conditional statements, circular statements and block statements of Verilog digital system design tutorial (with answers to thinking questions)
kettle庖丁解牛第14篇之JSON输入
Matlab draw five-star red flag
To remember the composition ~ the pre order traversal of binary tree
I don't understand time, timestamp and time zone. Look at this article
Your guide to lowering your cholesterol with TLC (continuously updated)
First principle mind map
How to protect open source projects from supply chain attacks - Security Design (1)
108. 将有序数组转换为二叉搜索树