Skip to content

Instantly share code, notes, and snippets.

@adjohu
Created February 27, 2013 11:03
Show Gist options
  • Save adjohu/5047141 to your computer and use it in GitHub Desktop.
Save adjohu/5047141 to your computer and use it in GitHub Desktop.
Simple model class
var A = function (props) {
this.properties = props;
this.constructor.addModel(this);
};
A.models = [];
A.addModel = function (model) {
model.properties.id = this.models.length + 1;
this.models.push(model);
};
A.all = function () {
return this.models;
};
A.where = function (props) {
return this.models.filter(function (model) {
for (var prop in props) {
if (model.properties[prop] != props[prop]) return false;
}
return true;
});
};
A.find = function (id) {
return this.where({id: id});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment