JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
JavaScript
(function() {
console.log(Backbone);
window.App = {
Model: {},
Collection: {},
View: {}
};
App.Model.Whatever = Backbone.Model.extend({});
App.Collection.Whatever = Backbone.Collection.extend({
model: App.Model.Whatever,
initialize: function(models, options) {
this.getModels();
_.bindAll(this, 'getModelsWithBindAll');
this.getModelsWithBindAll();
console.log(this);
console.log(models);
models.each(function(model) {
console.log(model);
});
},
getModels: function() {
console.log('in getModels');
console.log(this);
whateverCollection.each(function(model) {
console.log(model);
console.log(model.toJSON());
});
},
getModelsWithBindAll: function() {
console.log('in getModelsWithBindAll');
console.log(this);
whateverCollection.each(function(model) {
console.log(model);
console.log(model.toJSON());
});
}
});
var whateverCollection = new App.Collection.Whatever([
{
name: 'jim',
title: 'boss'
},
{
name: 'tom',
title: 'worker'
}
]);
console.log('program code');
console.log(whateverCollection);
})();