当前位置:网站首页>JS arguments

JS arguments

2022-06-25 04:36:00 Liujiayi_

Catalog

(1) When the function is called , The browser passes in two implicit parameters at a time ;

(1) Verify that... Exists arguments

(2)arguments.length It can be used to get the length of arguments

(3) It has an attribute called callee


(1) When the function is called , The browser passes in two implicit parameters at a time ;

1. The context object of the function this
2. The object that encapsulates the argument arguments

(1) Verify that... Exists arguments

    <script>
      function fun() {
        console.log(arguments);
      }
      fun();
    </script>

  So there is ;

- arguments It's a Class array object , It can also manipulate data through indexes , You can also get the length

- When the function is called , All the arguments we pass will be in arguments Kept in
 

Class array object : Let's verify that it's not an array ( The two methods )

    <script>
      function fun() {
        console.log(arguments instanceof Array);
        console.log(Array.isArray(arguments));
        // console.log(arguments.length);
      }
      fun();
    </script>

Obviously not an array -------- It's an array of classes  

(2)arguments.length It can be used to get the length of arguments

    <script>
      function fun() {
        console.log(arguments.length);
      }
      fun(" Liu ", " home ", " yi ");
    </script>

- Even if we don't define formal parameters , It can also be done through arguments To use arguments ,
Just more trouble
arguments[0] Represents the first argument
arguments[1] Represents the second argument ........

(3) It has an attribute called callee


This property corresponds to a function object , Is the object of the function that you are currently pointing to

    <script>
      function fun() {
        console.log(arguments.callee == fun);
      }
      fun();
    </script>



 

 

原网站

版权声明
本文为[Liujiayi_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250256377237.html