Показать сообщение отдельно
  #5 (permalink)  
Старый 28.03.2014, 17:34
Аватар для danik.js
Профессор
Отправить личное сообщение для danik.js Посмотреть профиль Найти все сообщения от danik.js
 
Регистрация: 11.09.2010
Сообщений: 8,804

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})));
__________________
В личку только с интересными предложениями
Ответить с цитированием