English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
This example analyzes the usage of the .length property of function names in JavaScript. Share it with everyone for reference, 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"> //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 //It is different from arguments.length, where arguments.length refers to the number of formal parameters passed in when the external call is made 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 on 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 Algorithms and Techniques'.
I hope the content described in this article will be helpful to everyone in designing JavaScript programs.
Statement: 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, and this website does not own the copyright. It 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 (Please replace # with @ when sending an email for reporting violations, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)