How to use JS to get function parameter name

Xiaobian to share the method of using JS to obtain function parameter name, I hope everyone will read this article, let us discuss together!

When visiting the, I saw a method of obtaining a function parameter name through JavaScript. I feel that it is very clever, read, let me know that it is useful.

  function getArgs (func) {// parentheses matching function parameters var args = func.toString (). Match (/ function \ s. *? \ (( [^)] *) \) /) [1]; // Decomposition parameter Number of argend (","). MAP (Function (arg) {// goes space and inline comment Return arg.replace / \\ \\ \\ \ \ \///,"").trim();} ).filter (Function (ARGS) {// Make sure no undefinedsreturn args;});}  

With this method, we can write a test function to test.

 Function Test (AGR1, Arg2, Arg3) {// Here is a comment / * Here is a comment * /} console.log (getargs (test));   
After reading the article, I believe you have a certain understanding of JS method to obtain the name of the function parameters, would like to know more about them, welcome attention Tumi cloud industry information channel, thank you for reading!

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment