Last active
December 10, 2015 03:18
-
-
Save robertcasanova/4373307 to your computer and use it in GitHub Desktop.
Using Mixin for sharing code within different Views
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
| 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