NkS
NkS

Reputation: 1280

In ember.js, what's the difference between mixin and extend?

What's is the difference between mixin and extend, when to use each one?

Upvotes: 25

Views: 7886

Answers (2)

raghul
raghul

Reputation: 1510

A mixin is a special kind of multiple inheritance. There are two main situations where mixins are used:

  1. You want to provide a lot of optional features for a class.
  2. You want to use one particular feature in a lot of different classes.

Upvotes: 3

Dan Gebhardt
Dan Gebhardt

Reputation: 3281

I wrote this article about Ember.Object which explains the differences in detail. Essentially, use extend to create a new class from a base class and use mixins to separate lateral concerns that you may want to include in any number of classes / objects. Mixins can be included in classes via extend or objects via create.

Upvotes: 34

Related Questions