The _.wrap() is used to wrap a function inside other function. It means that the first calling function (a function which is calling another function in its body) is called and then the called function is being executed. If the calling function does not call the called function then the second function will not be executed.
_.wrap( function, wrapper )
Parameters: This function accepts two parameters which are listed below:
- function: This parameter is used to hold the function name.
- wrapper: This parameter is used to hold the wrapper function which wrap first function.
Return value: It returns the output of both the function involved in the process.
Passing no arguments of both functions of _.wrap() function: The function is called which is passed to the console.log() function. That function body contains the _.wrap() function which calls the other function. Then the other function body gets executed and finally the control returns to the called function.
Passing an argument to the second function of _.wrap() function: Passing the argument to the second function from the first function definition. In the definition, the parameter to the second function will be passed by giving the parameter inside double quotes (” “) inside the brackets. The function will work as earlier like first, the first function which is called will be executed and then the first function will be executed.
Passing special characters as argument to the second function of _.wrap() function: Passing special characters to the second function then the _.wrap() function will work in the same way. It takes the special character as a normal character and then works in the same way. The first function will be called and then it’s body will be executed. After that when the first function is called inside the second function, the second function body will get executed.
Passing numbers as arguments to the second function of the _.wrap() function: The second function will also consider the numbers in the same way as they consider the characters. This will give the output accordingly.
Note: These commands will not work in Google console or in Firefox as for these additional files need to be added which they didn’t have added. So, add the given links to your HTML file and then run them.