function Collection(items) {
this.items = items;
}
Collection.prototype.query = function(whereClause) {
return this.items.filter(function(item) {
for (var key in whereClause) {
if (item[key] != whereClause[key])
return false;
}
return true;
});
};
var collection = new Collection([{id:1,location:'3'}, {id: 2, location: '3'}]);
alert(JSON.stringify(collection.query({id: 2})));
alert(JSON.stringify(collection.query({location: 3, id: 1})));