English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Analyse de l'utilisation de la propriété length du nom de la fonction dans Javascript (comparaison avec arguments.length)

Cette exemple analyse l'utilisation de la propriété length du nom de la fonction en Javascript. Partageons-le avec tout le monde pour la référence, voici les détails :

<!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">
    //The .length of the function name indicates the number of parameters defined in the function definition. Here, the sayHi function defines a parameter a, so the output is1
    //and arguments.length are not the same, arguments.length refers to the number of formal parameters passed in when externally called
    window.onload = function () {
      sayHi();
    }
    function sayHi(a) {
      alert(sayHi.length);  //Prints out1
    }
    alert(sayHi.length);    //It also prints out1 
  </script>
</head>
<body>
</body>
</html>

Readers who are interested in more content related to JavaScript can check the special topics of this site: 'Summary of JavaScript Array Operation Techniques', 'Summary of JavaScript Mathematical Operation Usage', 'Summary of JavaScript Data Structure and Algorithm Techniques', 'Summary of JavaScript Switching Effects and Techniques', 'Summary of JavaScript Search Algorithm Techniques', 'Summary of JavaScript Animation Effects and Techniques', 'Summary of JavaScript Error and Debugging Techniques', and 'Summary of JavaScript Traversal Algorithm and Techniques'.

I hope the content described in this article will be helpful to everyone in designing JavaScript programs.

Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (when sending an email, please replace # with @ to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)

Vous pourriez aussi aimer