Returning a reference in JavaScript
<p>Here is the code:</p>

<p><a href="http://jsfiddle.net/GKBfL/" rel="nofollow">http://jsfiddle.net/GKBfL/</a></p>

<p>I am trying to get <code>collection.prototype.add</code> to return a reference such that the final alert will display <code>testing, testing, 123, testing</code>. Is there a way to accomplish what I'm trying to do here?</p>

<p>HTML:</p>

<pre><code>&lt;span id="spantest"&gt;testing, testing, 123, testing&lt;/span&gt;​
</code></pre>

<p>JavaScript:</p>

<pre><code>var collection = function () {
   this.items = {};   
}

collection.prototype.add = function(sElmtId) {
    this.items[sElmtId] = {};
   return this.items[sElmtId];
}

collection.prototype.bind = function() { 
    for (var sElmtId in this.items) {
        this.items[sElmtId] = document.getElementById(sElmtId);
    }
}
var col = new collection();
var obj = {};
obj = col.add('spantest');
col.bind();
alert(obj.innerHTML);​
</code></pre>
