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