dimanche 20 novembre 2016

Javascript get Property name from class declaration

Lets have a javascript "class"

  var User= function(id, firstName, lastName) {
      this.id=id;
      this.firstName=firstName;
      this.lastName=lastName
  }
  var user = new User (1,"I", "am");

I would like to reference a specific field name of user class, lets say the id field, without using the String "id"

... something like (user->id).getName(); (should return the String "id")

Note : Enumerating the user Object properties is not helping me since I will have to choose among them using the String "id" and so hard code somewhere

hope I am clear.

The goal is to select some properties of user Object to fill in a table without hard coding the object properties as Strings. Thanks





Aucun commentaire:

Enregistrer un commentaire