Share Code with Mixins
While utilities are a useful way to share one function, they don’t cover every possible need. Our validation utility function could have been more useful if it were in the form of a collection of functions that could be used in many places. To do this, we can create a mixin. In Ember, a mixin is a collection of properties and functions that can be used in any class that depends on them. The definition of these properties and functions resides in the mixin, and is available in any class that takes advantage of the mixin.
Because a mixin can contain properties and functions, it can be used not only to abstract behavior, but to abstract state as well. When a class inherits this mixin, the properties and functions of that ...
Get Deliver Audacious Web Apps with Ember 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.