Let's say you have an object and you want to get a string of the name of the property you are referencing. Is there a name for that? I mean it's some sort of
reflection but is there a more specific name for it and do languages implement it in standard way?
For example, this feature exists for class based objects using
var person:Person = new Person(); var nameOfClass:String = person.toString(); trace(nameOfClass); // traces "Person" or "com.mydomain.model.Person"
But since properties can be null or undefined you can't use
toString() as it will throw an error or if it's not
null it will get the
var person:Person = new Person(); var nameOfProperty:String = person.name.toString(); // error is thrown when null person.name = "John"; person.name.toString(); // traces the value "John" not the type
So I'm guessing some languages would have a global function like so.
var person:Person = new Person(); var nameOfProperty:String = propertyName(person.name); trace(nameOfProperty); // traces "name" nameOfProperty = propertyName(person.zipCode); trace(person.zipCode); // traces "zipCode"
Is there a specific name for this feature and if so how is implemented?