What is the difference between .create()
and .createWithMixins()
? I am not able to find any documentation regarding this. When I create a view instance using .create()
and call this._super()
in the didInsertElement
method then, following error is thrown:
Ember.Object.create no longer supports defining methods that call _super.
But, when I replace .create()
with .createWithMixins()
everything works fine. Here is the code and the sample js fiddle :
App.SampleView = Ember.View.create({
sampleProperty : "a",
didInsertElement : function(){
this._super();
this.set("sampleProperty", "b");
}
});
From Wikipedia:
In Ember instances of objects are created with the
create
method with no arguments, or with a single hash(kvo) that represent the properties of that type, and they will be automatically populated. Example:On the other hand,
crateWithMixins
, allow you to mix another class definition into a single object instance or into another class. So let's say you have the sameSomeClass
above, but you don't want to sub-class it viaextend
and create another type. In this case you can use aMixin
to make sure that only that one instance will have that definition of the two classes. Example:However, if you want to create a new class with a
Mixin
, you canextend
Em.Object
, passing theMixin
as the first argument, as follows:Check out the API Documentation as well as this JSFiddle.
Edit: As for
_super()
, you only use this when you create a new class (viaextend
). When youcreate
instances of existing classes, you shouldn't call_super()
.Another thing. I see you're trying to
create
aView
directly. I believe, based on your code, you should be extendingEmber.View
and let the framework create instance for your at the appropriate time. If you create manually, you'll be responsible for some parts of its workflow like appending it to the DOM, removing it, etc. Maybe I don't see the whole picture, but based on this code alone, I think you should not callcreate
there and callextend
instead, and then you'll be able to call_super()