If you are in need of variable names, you can use a method like the one demonstrated below:
function getVariableNames(arg1, arg2, Arg3){
var Args = Array.apply(null, arguments);debugger
var ArgNames = (getVariableNames+"").match(/\(([.\s\S]*?)\)/)[1].replace(/[\s ]/g,"");
ArgNames = !ArgNames ? [] : ArgNames.split(",");
for(var i in ArgNames) console.log(ArgNames[i]+": "+Args[i]);
console.log("Value of arguments: "+Args);
console.log("Name Of arguments: "+ArgNames);
};
getVariableNames(100,40,"BTTOLA");
This approach works well even if the function has no arguments or is defined within a few lines.
The following types of functions are supported by this approach:
function example(a, b){...};
function example(
a,
b
){
...
};
var example=function(a, b){...};
Alternatively, for an Arrow
function like this:
var example = (a, b) => {...}
You can implement it in a similar way (which is effective for both Arrow and simple functions):
var example = (arg1, arg2, Arg3) => {
var ArgNames = (example+"").match(/\(([.\s\S]*?)\)/)[1].replace(/[\s ]/g,"");
ArgNames=ArgNames?ArgNames.split(","):[];
console.log(ArgNames);
};
example(100,40,"BTTOLA");