JSFiddle - React, Tailwind, and code Playground

by Eric Howe

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone-min.js"></script>

JavaScript

var M = Backbone.Model.extend({});
var C = Backbone.Collection.extend({
    model: M
});
var V = Backbone.View.extend({
    initialize: function() {
        this.listenTo(this.collection, 'reset add change', this._setCollection);
    },
    _setCollection: function() {
        if(arguments[0] instanceof M
        && arguments[1] instanceof C) {
            console.log('add');
        }
        else if(arguments[0] instanceof C) {
            console.log('reset');
        }
        else if(arguments[0] instanceof M
             && arguments.length == 2) {
            console.log('change');
        }
        else {
            console.log('confusion!');
        }
    }
});

var c = new C;
var v = new V({ collection: c });
c.add({id:1});
c.at(0).set({ a: 'b' });
c.reset();