JS: join()-ing an array of objects
<p>Say I have an array of objects that I want to be able to access as hashes sometimes (to change their values, eh?) and sometimes print.    </p>

<pre><code>var test = { members : [] };
test.addMember = function(name, value) { 
    this.members[name] = { name : name, value : value }; 
    this.members[name].toString = function() { 
        return this.name + " has a " + this.value; };
};
test.toString = function() { 
    return this.members.join(" and ");
};
test.addMember("a", "a value");
test.addMember("b", "b value");
alert(test);
</code></pre>

<p>My Goal here is to have test.toString() return:</p>

<pre><code>a has a value and b has b value
</code></pre>

<p>or what-have-you. I was reading on the MDN, and it seems that JavaScript 1.8.5 (or some subrevision) will have a join() that calls toString(). Am I stuck?</p>

<p>Thanks!</p>

<p>EDIT: Here's my FINAL design, with a modify and delete function included (in case anyone was curious)!</p>

<pre><code>var test = { 
    members : [],
    modifyMember : function(name, value) {
        var index = this.members.indexOf(this.members[name]);
        if(index &lt; 0) {
            return;
        }
        this.members[index].value = this.members[name].value = value;
    },
    addMember : function(name, value) { 
        if(this.members[name]) { 
            this.modifyMember(name, value);
            return;
        }
        this.members[name] = { 
            name : name, 
            value : value,
            toString : function() { 
                return this.name + " has " + this.value; 
            },
        }; 
        this.members.push(this.members[name]);
    },
    removeMember : function(name) { 
        if(!this.members[name]) return;
        this.members.splice(this.members.indexOf(this.members[name]), 1);
        delete this.members[name];
    },
    toString : function() {
        return this.members.join(" AND ");
    } 
};
</code></pre>
