In my application, I receive a collection of Comments with JSON.
Then, I want to add functions to every item in this collection, so for example if a Comment has comment.first_name and comment.last_name, I want to build comment.full_name().
So far, I'm doing:
comment.full_name = function() { return this.first_name+" "+this.last_name }
My question is, since there are many comments (and other methods more complex than this one), how could I use prototypes or constructors to add the same function to every item in the collection, without inserting it into each element?
EDIT:
Here is an example of code:
comments = ({"1": {"first_name":"John", "last_name":"Silver"}, "2": {"first_name":"Jack", "last_name":"Sparrow"}})
Now, I'm looking for something that will return
comments[1].name() //=> John Silver
comments[2].name() //=> Jack Sparrow