What’s the difference between ember.js Object methods extend and create?
TLDR: You will find the answer in Ember guides: classes and instances.
Sometimes I see that one in the examples and sometimes the other. In particular, what’s the difference between Em.Application.extend({}) and Em.Application.create({})?
If I declare my app like this, what does it mean?
Ember.Application.create({
MyController : Ember.ArrayController.extend({
}),
});
How can I access the instance of MyController? Do I need to create it somehow? I need to push some data into it.
The dead simple answer is that
extenddefines a new JS Class which inherits from the class you’re extending, but does not create an instance of that class.createcreates an instance of the class.Em.Applicationis a particular case, because you’re creating a namespace, not an object instance. I don’t know when you’d ever want toextendEm.Application.App = Em.Application.create(); // I have a new Em.Application namespace App.A = Em.Object.extend(); // I have defined a new class, App.A, // which inherits from Em.Object var a = App.A.create(); // a now contains an instance of App.A.I’d suggest you read “Naming Conventions“, too.
ETA: And “Understanding Ember Objects“, as suggested in zaplitny’s comment.