Skip to content

Instantly share code, notes, and snippets.

@robertcasanova
Last active December 10, 2015 03:18
Show Gist options
  • Select an option

  • Save robertcasanova/4373307 to your computer and use it in GitHub Desktop.

Select an option

Save robertcasanova/4373307 to your computer and use it in GitHub Desktop.
Using Mixin for sharing code within different Views
App.Mixins.Navigation = {
toggle: function() { /* ... */ },
open: function() { /*... */ },
close: function() { /* ... */ }
};
App.Menu = Backbone.View.extend({
// I need to know how to toggle, open, and close!
});
_.extend(App.Views.Menu.prototype, App.Mixins.Navigation);
App.Tabs = Backbone.View.extend({
// I too need to know how to toggle, open, and close!
});
_.extend(App.Views.Tabs.prototype, App.Mixins.Navigation);
//different syntax
App.Views.Menu = Backbone.View.extend(
_.extend({}, App.Mixins.Navigation, {
// (Methods and attributes here)
}));
App.Views.Tabs = Backbone.View.extend(
_.extend({}, App.Mixins.Navigation, {
// (Methods and attributes here)
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment