


What are arguments?
arguments is an array-like object created when a function is called but is not an array object. It stores the parameters actually passed to the function and is not limited to the parameter list declared by the function.
Nima, what do you mean?
Write a demo and see the code below
<!DOCTYPE html> <head> <title>arguments</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <script> function obj(){ //利用instanceof判断arguments console.log( 'arguments instanceof Array? ' + (arguments instanceof Array) ); console.log( 'arguments instanceof Object? ' + (arguments instanceof Object) ); console.log(arguments); } obj(); </script> </body> </html>
Run this code and use the chrome debugger to get the following picture
I use instanceof to determine arguments. From the printing effect, arguments are an object.
Then expand the printed arguments. As you can see from the picture above, it includes many attributes, including callee.
Next, we modify the above code and pass parameters to it when calling the obj function, but the obj function has no parameters.
See the specific code below
<!DOCTYPE html> <head> <title>arguments</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <script> function obj(){ console.log( 'arguments instanceof Array? ' + (arguments instanceof Array) ); console.log( 'arguments instanceof Object? ' + (arguments instanceof Object) ); console.log(arguments); } //向obj传递参数 obj('monkey','love',24); </script> </body> </html>
Through the chrome debugger, you can get the picture below
As you can see, arguments contains the three parameters "monkey", "love", and 24 that we passed to it.
So, why arguments are the stored parameters actually passed to the function, rather than the parameters declared by the function.
What is a callee?
callee is a member of the arguments object, and its value is "the Function object being executed".
What does it mean?
Let’s write a demo and see the output.
See the code and result diagram below
<!DOCTYPE html> <head> <title>callee</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <script> function obj(){ //利用callee console.log(arguments.callee); } obj(); </script> </body> </html>
As you can see from the picture above, arguments.callee is a function pointing to the arguments object, which is obj in this case.
What is caller?
caller is an attribute of the function object, which stores the function that calls the current function.
Note, it is a call. It doesn’t just include closures. If there is no parent function, this is null.
It’s still the same as before, let’s write a demo all the time.
The code is as follows:
<!DOCTYPE html> <head> <title>caller</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <script> //child是parent内的函数,并在parent内执行child function parent(){ function child(){ //这里child的父函数就是parent console.log( child.caller ); } child(); } //parent1没有被别人调用 function parent1(){ //这里parent1没有父函数 console.log(parent1.caller); } //parent2调用了child2 function parent2(){ child2(); } function child2(){ console.log(child2.caller); } /*执行 parent里嵌套了child函数 parent1没有嵌套函数 parent2调用了child2,child2不是嵌套在parent2里的函数 */ parent(); parent1(); parent2(); </script> </body> </html>
Open the chrome debugger and you can see the renderings
Based on the code and the above picture, do you understand the caller now?

去掉重复并排序的方法:1、使用“Array.from(new Set(arr))”或者“[…new Set(arr)]”语句,去掉数组中的重复元素,返回去重后的新数组;2、利用sort()对去重数组进行排序,语法“去重数组.sort()”。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于Symbol类型、隐藏属性及全局注册表的相关问题,包括了Symbol类型的描述、Symbol不会隐式转字符串等问题,下面一起来看一下,希望对大家有帮助。

怎么制作文字轮播与图片轮播?大家第一想到的是不是利用js,其实利用纯CSS也能实现文字轮播与图片轮播,下面来看看实现方法,希望对大家有所帮助!

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于对象的构造函数和new操作符,构造函数是所有对象的成员方法中,最早被调用的那个,下面一起来看一下吧,希望对大家有帮助。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于面向对象的相关问题,包括了属性描述符、数据描述符、存取描述符等等内容,下面一起来看一下,希望对大家有帮助。

方法:1、利用“点击元素对象.unbind("click");”方法,该方法可以移除被选元素的事件处理程序;2、利用“点击元素对象.off("click");”方法,该方法可以移除通过on()方法添加的事件处理程序。

本篇文章给大家带来了关于JavaScript的相关知识,其中主要介绍了关于BOM操作的相关问题,包括了window对象的常见事件、JavaScript执行机制等等相关内容,下面一起来看一下,希望对大家有帮助。

foreach不是es6的方法。foreach是es3中一个遍历数组的方法,可以调用数组的每个元素,并将元素传给回调函数进行处理,语法“array.forEach(function(当前元素,索引,数组){...})”;该方法不处理空数组。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use
