API Docs for: 1.0 pre
Show:

Ember.Mixin Class

The Ember.Mixin class allows you to create mixins, whose properties can be added to other classes. For instance,

App.Editable = Ember.Mixin.create({
  edit: function() {
    console.log('starting to edit');
    this.set('isEditing', true);
  },
  isEditing: false
});

// Mix mixins into classes by passing them as the first arguments to
// .extend.
App.CommentView = Ember.View.extend(App.Editable, {
  template: Ember.Handlebars.compile('{{#if view.isEditing}}...{{else}}...{{/if}}')
});

commentView = App.CommentView.create();
commentView.edit(); // outputs 'starting to edit'

Note that Mixins are created with Ember.Mixin.create, not Ember.Mixin.extend.

Note that mixins extend a constructor's prototype so arrays and object literals defined as properties will be shared amongst objects that implement the mixin. If you want to define a property in a mixin that is not shared, you can define it either as a computed property or have it be created on initialization of the object.

//filters array will be shared amongst any object implementing mixin
App.Filterable = Ember.Mixin.create({
  filters: Ember.A()
});

//filters will be a separate  array for every object implementing the mixin
App.Filterable = Ember.Mixin.create({
  filters: Ember.computed(function(){return Ember.A();})
});

//filters will be created as a separate array during the object's initialization
App.Filterable = Ember.Mixin.create({
  init: function() {
    this._super();
    this.set("filters", Ember.A());
  }
});

Item Index

Methods

Methods

apply

(
  • obj
)

Parameters:

  • obj Object

Returns:

applied object

create

(
  • arguments
)
static

Parameters:

  • arguments Object multiple

detect

(
  • obj
)
Boolean

Parameters:

  • obj Object

Returns:

Boolean:

reopen

(
  • arguments
)

Parameters:

  • arguments Object multiple