Adding the same function to many elements (using js prototypes?)
<p>In my application, I receive a collection of Comments with JSON.</p>

<p>Then, I want to add functions to every item in this collection, so for example if a Comment has <code>comment.first_name</code> and <code>comment.last_name</code>, I want to build <code>comment.full_name()</code>.</p>

<p>So far, I'm doing:</p>

<pre><code>comment.full_name = function() { return this.first_name+" "+this.last_name }
</code></pre>

<p>My question is, since there are many comments (and other methods more complex than this one), how could I use <strong>prototypes</strong> or <strong>constructors</strong> to add the same function to every item in the collection, without inserting it into each element?</p>

<p><strong>EDIT</strong>:</p>

<p>Here is an example of code:</p>

<pre><code>comments = ({"1": {"first_name":"John", "last_name":"Silver"}, "2": {"first_name":"Jack", "last_name":"Sparrow"}})
</code></pre>

<p>Now, I'm looking for something that will return</p>

<pre><code>comments[1].name() //=&gt; John Silver
comments[2].name() //=&gt; Jack Sparrow
</code></pre>
