I don't think the thing you want to achieve is possible. You can look at the stack trace at debug time, but I will give you further information and ideas here:
You could have a development policy in your team to name outside variables the same way as the parameters are at functions whenever possible. If you do so, this post will become useful.
You might introduce a policy to pass objects to functions, like {name: 'John', age: 3}
and then you will know the keys.
You could create a Trackable
prototype which would have a key
and a value
, like this:
function Trackable(name, value) {
this.name = name;
this.value = value;
}
and pass trackables to functions when their names will be needed, thus you will call testVar(new Trackable('myVar', myVar))
and inside you will check param1.value against undefined and if it is undefined, then use the name in your report.