0

Approximately half of the views in my application contain a small gear icon that allows users to click and open a tools menu associated with that view. While the contents of each of these menus will likely be different, the act of clicking the gear to open the menu is always exactly the same.

What's the best way to go about storing and reusing the same function for opening/closing this menu that appears in many views?

MORE

Similarly, many of my views are collapsible (meaning you can click an arrow in the view to hide its contents). I have a single function that controls that and would like to easily be able to reuse that across the application.

Brandon Durham
  • 7,096
  • 13
  • 64
  • 101

1 Answers1

1

Use mixins, as explained here: Proper way of doing view mixins in Backbone

Mixins allow you to defined the shared functionality within an object. Then, you simply need to extend the objects to which you want to add this functionality, using underscore's extend method.

Community
  • 1
  • 1
David Sulc
  • 25,946
  • 3
  • 52
  • 54