In my quest to delve deeper into JavaScript, I've embarked on creating my very own MVC library. My current investigation involves examining the source code of backbone.js which can be found here.
When defining a Collection in backbone.js, it involves assigning it to a JavaScript variable as shown below:
var AppCollection = Backbone.Collection.extend({ model: BACKBONE_MODEL })
The creator employs underscore internally and utilizes the `prototype` for the `Collection`, extending it with underscore's `_.extend()` method like so:
_.extend(Collection.prototype, Events, {})
. The empty object passed in serves as a container for all the methods related to the Collection object, such as the `model` key containing the Model object previously defined.
I'm intrigued by the idea of sidestepping the underscore dependency and incorporating my custom prototypical methods for the Collection. How can I introduce an object with the `model` key into my Collection object?
Below is a snippet of what I've been working on:
(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;
}));