I am trying to dig deep into javascript by creating my own MVC library. I am looking into backbone.js source code https://github.com/jashkenas/backbone/blob/master/backbone.js
When you define a Collection in backbone.js you would assign it to a javascript variable like this var AppCollection = Backbone.Collection.extend({ model: BACKBONE_MODEL })
Internally the creator uses underscore and passes the prototype for the Collection into underscore's _.extend() method like this _.extend(Collection.prototype, Events, {}), where the empty object argument resides in the example I have written is where the author adds all the methods for the Collection object, i.e the model key which value is the Model object defined earlier in the library.
I am curious, how can I avoid the underscore dependency and add my own prototypical methods for the Collection, specifically how can I pass in an object with the key model into my own Collection object?
Here is what I have so far.
(function(Pigeon, root, factory) {
root[Pigeon] = factory();
} ('Pigeon', this, function() {
var Pigeon = {};
// Model
var Model = Pigeon.Model = function() {
this.attributes = {};
};
// Collection
var Collection = Pigeon.Collection = function(models) {
};
// View
Pigeon.View = {};
// Controller
Pigeon.Controller = {};
return Pigeon;
}));