Skip to content

Instantly share code, notes, and snippets.

@4bu
Created December 13, 2011 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 4bu/1472559 to your computer and use it in GitHub Desktop.
Save 4bu/1472559 to your computer and use it in GitHub Desktop.
var PersonModel = Backbone.Model.extend();
var PersonView = Backbone.View.extend({
initialize: function () {
_.bind(this, 'render’);
this.model.bind(‘change:name’, this.render);
},
render: function () {
$(‘body’).html(this.model.get(‘name’));
}
});
var personModel = new PersonModel();
personModel.set({name: ‘Marco Francke’});
var personView = new PersonView({
model: personModel
});
// initial render the name
personView.render();
// new name
personModel.set({name: ’BackboneJS’});
// another new name
personModel.set({name: ’Backbone rocks’});
@mrienstra
Copy link

I suggest updating this to my forked version, which fixes smart quotes issue, and also changes view binding to something that works (see http://stackoverflow.com/questions/7087564/what-is-the-difference-between-these-backbone-underscore-bind-methods ).

Oh and I added a delay to second name change so that both can be seen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment