Possible Duplicate:
Determine original name of variable after its passed to a function.
I would like to know if its possible to get the actual name of a variable.
For example:
var foo = 'bar';
function getName(myvar) {
//some code
return "foo"
};
So for getName(foo) will return “foo”
Is that possible ?
Thanks.
I don’t think it is possible. When you call a function you pass an object, not a variable. The function doesn’t care where the object came from.
You can go the other way though if you call your function as follows:
Or pass both the value and the name: