I need to add some more OO flavor to my pure JS objects. Basically, I have on the server side
class Superitem {
List<Item> items;
Whatever whatever;
}
class Item {
List<Subitem> subitems;
Whatever whatever;
}
class Subitem {
List<Whatever> whatevers;
}
In the client, I get a superitem as a plain Javascript hash and would like to convert it to something better. I started like
Superitem(plain) {
this.items = plain && plain.items || [];
this.whatever = new Whatever(plain.whatever);
}
but it's too verbose (my real classes are more complicated) and I rather doubt if its worth the effort. I'm not trying to mimic Java in Javascript, just want to add a few useful methods. Is there a better way? Thing like $.extend
seem to be useless here.