Skip to content

Instantly share code, notes, and snippets.

@loganfsmyth
Last active December 17, 2015 15:18
Show Gist options
  • Save loganfsmyth/5630257 to your computer and use it in GitHub Desktop.
Save loganfsmyth/5630257 to your computer and use it in GitHub Desktop.
Some basic examples of using jQuery vs using Backbone.Native.
events: {
'click .child': 'clickChildEvent'
},
// With jQuery
clickChildEvent: function(event){
$(event.currentTarget).toggleClass('clicked');
},
// With Backbone.Native
clickChildEvent: function(event, childElement){
childElement.classList.toggle('clicked');
}
render: function(){
// With jQuery
this.$('.child').each(function(i, childElement){
var subview = new App.Views.Child();
$(childElement).append(subview.render().$el);
});
// With Native APIs
_.forEach(this.el.querySelectorAll('.child'), function(childElement){
var subview = new App.Views.Child();
childElement.appendChild(subview.render().el);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment