Last active
August 29, 2015 14:15
-
-
Save nakajmg/e11e2af9c0aadb8a192d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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