Using mix-ins to add behavior

We've seen how to use inheritance and composition to add behavior. There is a different method of composition that appends behavior onto existing classes without inheritance. Using mix-ins attaches properties to an object instance at runtime.

In this recipe, we'll see how to use the mix-ins to add shared behavior to classes without inheritance.

Get ECMAScript Cookbook 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.