Skip to content

Instantly share code, notes, and snippets.

@nakajmg
Last active August 29, 2015 14:15
Show Gist options
  • Save nakajmg/e11e2af9c0aadb8a192d to your computer and use it in GitHub Desktop.
Save nakajmg/e11e2af9c0aadb8a192d to your computer and use it in GitHub Desktop.
function Model(name) {
this.name = name;
}
function Collection(models) {
this.models = models || [];
}
Collection.prototype.showName = function() {
this.models.forEach(function(model) {
console.log(model.name);
});
}
Collection.prototype.add = function(model) {
this.models.push(model);
}
var model1 = new Model("hoge1");
var model2 = new Model("hoge2");
var model3 = new Model("hoge3");
var model4 = new Model("hoge4");
var collection1 = new Collection();
var collection2 = new Collection();
collection1.add(model1);
collection1.add(model3);
collection2.add(model2);
collection2.add(model4);
collection1.showName();
collection2.showName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment