Home > Web Front-end > JS Tutorial > Analysis on usage of function name .length attribute in Javascript (compared to arguments.length)

Analysis on usage of function name .length attribute in Javascript (compared to arguments.length)

高洛峰
Release: 2017-01-04 17:02:08
Original
1919 people have browsed it

The example of this article analyzes the usage of the function name.length attribute in Javascript. Share it with everyone for your reference, the details are as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
  <script type="text/javascript">
    //函数名.length表示的是函数定义的参数的个数,这里sayHi函数定义了一个参数a,所以输出1
    //和arguments.length不一样,arguments.length指的是外部调用时传入的形参的个数
    window.onload = function () {
      sayHi();
    }
    function sayHi(a) {
      alert(sayHi.length);  //打印出1
    }
    alert(sayHi.length);    //也是打印出1 
  </script>
</head>
<body>
</body>
</html>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

For more related articles on the usage analysis of function name .length attribute in Javascript (compared to arguments.length), please pay attention to the PHP Chinese website!


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template