Given a Javascript object with the method myobject.mymethod
the name of the method can be retrieved for printing or whatever using myobject.mymethod.name
.
How do I achieve the same thing for property myobject.myproperty
.
UPDATE: Specific scenario.
I have an object from a third party library that defines a load of constant values used throughout its api
obj = {
CONST1 = 1;
CONST2 = 2;
CONST3 = 3;
// ...
}
I'm handling events that are called with these values and want to log what each event is called with. The raw values aren't useful in a log, so I want to log the constant names, ideally without a switch statement mapping values to hardcoded strings or having to define my own lookup table.
The library object has a load of other crap defined on it too, so just looking up the property using the value is not a reliable solution.