Ember.Mixin Class packages/ember-metal/lib/mixin.js:336

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 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.

Show:

Methods

Show:

apply

(obj)

Parameters:

obj

Returns:

applied object

create

(arguments) static

Creates an instance of a class. Accepts either no arguments, or an object containing values to initialize the newly instantiated object with.

1
2
3
4
5
6
7
8
9
10
11
App.Person = Ember.Object.extend({
  helloWorld: function() {
    alert("Hi, my name is " + this.get('name'));
  }
});

var tom = App.Person.create({
  name: 'Tom Dale'
});

tom.helloWorld(); // alerts "Hi, my name is Tom Dale".

create will call the init function if defined during Ember.AnyObject.extend

If no arguments are passed to create, it will not set values to the new instance during initialization:

1
2
var noName = App.Person.create();
noName.helloWorld(); // alerts undefined

NOTE: For performance reasons, you cannot declare methods or computed properties during create. You should instead declare methods and computed properties when using extend.

Parameters:

arguments

detect

(obj) Boolean

Parameters:

obj

Returns:

Boolean

reopen

(arguments)

Parameters:

arguments