#643

A simple playground for learning backbone.js without having to install or configure anything yourself.

HTML

<script src="http://documentcloud.github.com/underscore/underscore.js"></script>
<script src="http://documentcloud.github.com/backbone/backbone.js"></script>
<script src="https://getfirebug.com/firebug-lite.js"></script>

JavaScript

var Todo = Backbone.Model.extend({});

var Todos = Backbone.Collection.extend({
    model: Todo,
    url: '/gh/gist/response.json/1325366/',
    initialize: function(){
        this.bind('add', function(){
            console.log( this.length ); // won't fire
        }, this);
    }
});

var TodoView = Backbone.View.extend({
    initialize: function(){
        this.collection.bind( 'add', function(){
            console.log( this.collection.length ); // won't fire
        }, this);
    }
});

var myTodos = new Todos();

var t1 = new TodoView({ collection: myTodos });

myTodos.fetch({add:true});