Hello,
I have a class called User defined using MooTools Class. This class contains a getter called fullName (which manipulates firstName and lastName).
var User = new Class({
initialize:function(firstName, lastName){
this.firstName = firstName;
this.lastName = lastName;
},
fullName:function(){
return this.firstName + ' ' + this.lastName;
}
});
I can request a list of user profiles from the Java backend via AJAX and obtain a JSON response, basically a Javascript Array of Objects.
[{firstName:'John', lastName:'Doe'},{firstName:'Bob', lastName:'Hope'},....]
Is there a recommended way to convert this Array of DTOs into MooTools User Classes?
I could use Array.each and create a new instance of User by passing each DTO's firstName and lastName value in the constructor. Or maybe pass the DTO itself and use:
$each(userDTO,function(value,key){...}
I'm looking at $extend(myClass, myDTO)
which copies the properties of myDTO into myClass. Seems to be the easiest option at present.
It would be nice to know the recommended way to copy the DTO values. Many thanks!