Created
August 3, 2013 20:05
-
-
Save matthewhudson/6147803 to your computer and use it in GitHub Desktop.
Namespaced JS events
This file contains 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
var BaseView = Backbone.View.extend({ | |
el: $('body'), | |
initialize: function() { | |
// bind to the namespaced (for easier unbinding) event | |
// in jQuery 1.7+ use .on(...) | |
$(window).bind("resize.app", _.bind(this.resize, this)); | |
}, | |
remove: function() { | |
// unbind the namespaced event (to prevent accidentally unbinding some | |
// other resize events from other code in your app | |
// in jQuery 1.7+ use .off(...) | |
$(window).unbind("resize.app"); | |
// don't forget to call the original remove() function | |
Backbone.View.prototype.remove.call(this); | |
// could also be written as: | |
// this.constructor.__super__.remove.call(this); | |
}, ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment