var elems = { length: 0, add: function (elem) { Array.prototype.push.call(this, elem); }, gather: function (id) { this.add(document.getElementById(id)); } }; elems.gather("first"); console.log(elems.length == 1 && elems[0].id, "Verify that we have an element in our stash"); elems.gather("second"); console.assert(elems.length == 2 && elems[1].id, "Verify the other insertion");