As an extension of function functions, you need to establish a correct ing relationship between its form parameters and real parameters when a function is called. Let's take a look at the following example: as an extension of function functions, you need to establish a correct ing relationship between its form parameters and real parameters when a function is called.
Let's take a look at the following example:
function func1(arg1, arg2) { ... } var map = createArgumentMap(func1,'valueOfArg1', 'valueOfArg2'); console.log(map['arg1']); // writes 'valueOfArg1' console.log(map['arg2']); // writes 'valueOfArg2'
This ing function receives a function object as the first parameter, and a list of real parameters with unknown length. You must create a ing between the form parameters and the real parameter list of this function object, it is represented by an associated array and returned.
The real parameter list and function parameters are defined in the same order and are valid and valid parameters.
This topic is to create a ing between the form parameter and the real parameter. First, we obtain the toString () string form of the function object and extract its list of form parameters.
Then, because the length of the real parameter list is unknown, you can use the Array. prototype. slice Method to set its context to an arguments object, extract the real parameter from Index 1, and obtain the Array form of the real parameter list.
Finally, an associated array is created based on the real parameter list, the form parameter is key, the real parameter is value, and the associated array is returned.
This completes the parameter ing function.
String. prototype. trim = function () {return this. replace (/(^ \ s *) | (\ s * $)/g, "") ;}; var findArgs = function (funcStr) {var bracket1 = funcStr. indexOf ("("); var bracket2 = funcStr. indexOf (")"); var argsStr = funcStr. slice (bracket1 + 1, bracket2); var args = argsStr. split (","); return args. map (function (e) {return e. trim () ;}) ;}; function createArgumentMap (func) {var args = findArgs (func. toString (); var realArgs = Array. prototype. slice. call (arguments, 1); var map ={}; for (var I = 0; I
The above is the JavaScript interesting question: the ing between the form parameter and the real parameter. For more information, see the PHP Chinese website (www.php1.cn )!