Introduction to "JS" arguments parameters

Source: Internet
Author: User

When reading the Singalr.js source code, found a format method inside it:

  format: function  ()  {             /// <summary>usage: format ("Hi {0},  you are {1}! ", " Foo ",  100)  </summary>             var s = arguments[0];             for  (var i = 0; i < arguments.length  - 1; i++)  {                 s = s.replace ("{"  + i +  "}",  arguments[i + 1]);             }             return s;        }, 

Then found that there is no parameter in the Format function, or directly with the arguments receive, later learned a bit, found that the arguments method is very powerful, he can be called directly, regardless of the transmission of several parameters, he can receive, the above method realized. NET Inside String. Format () method. After making the parameter judgment, it is possible to use Arguments.length to determine whether the number of parameters passed is correct.

Finally, the definition of variable names is not arguments, which is like reserved words, so it is better not to conflict. The above code can be used as a method in the tool class, simple and rough and practical.

This article is from the "PZ Technical training base" blog, please be sure to keep this source http://panzi.blog.51cto.com/4738203/1590380

Introduction to "JS" arguments parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.