Last active
December 17, 2015 15:18
-
-
Save loganfsmyth/5630257 to your computer and use it in GitHub Desktop.
Some basic examples of using jQuery vs using Backbone.Native.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
events: { | |
'click .child': 'clickChildEvent' | |
}, | |
// With jQuery | |
clickChildEvent: function(event){ | |
$(event.currentTarget).toggleClass('clicked'); | |
}, | |
// With Backbone.Native | |
clickChildEvent: function(event, childElement){ | |
childElement.classList.toggle('clicked'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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