O'Reilly logo

SproutCore Web Application Development by Tyler Keating

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using mixins to share functionality

In the previous section we defined subclasses of SC.Object that inherit functionality from their parent classes. However, inheritance is too rigid for sharing code among classes that may not directly inherit from a shared parent.

For instance, in a previous example we defined a MyApp.Vehicle class and a MyApp.Car subclass of it. The MyApp.Car subclass added a topSpeed property supposedly unique to cars, but of course, topSpeed is not unique to cars. What if we had MyApp.Truck, MyApp.Boat, MyApp.Plane, MyApp.Helicopter, and other vehicle types? Some of these types will share common traits, such as top speed, but not all traits will be common to all vehicles, such as maximum altitude. How then would we subclass ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required