Javascript: Get Names Of Actual Arguments Passed In A Function
Solution 1:
I need that because the names also contain some information which I need in my function logic
if i call func(a,b,c,d) then there is one flow if logic in func and if I call it with func(l,m,n,d) then the logic flow in func algorithm changes and accordingly the output will change too
There is something profoundly wrong with your understanding of JS, or your conception of your problem, or more likely both.
Functions cannot know, and do not know, and must not know, and have no reason to need to know, what variables, values, or expressions were used in calling them.
I have no idea if this will solve your problem, whatever it is, but consider doing the following instead:
func({a,b,c,d});
The {a,b,c,d}
format creates an object with keys of a
etc. whose values are the variable a
. This is ES6 syntax. In ES5:
func({a:a,b:b,c:c,d:d});
Then, in your function, you can look at the keys in the object passed in as a parameter.
Post a Comment for "Javascript: Get Names Of Actual Arguments Passed In A Function"