This screencast : http://www.embercasts.com/episodes/getting-started-with-ember-model used Ember.model
to create a person model like this:
App.Person = Ember.Model.extend({
name : Ember.attr()
})
The docs give this example using Ember.Object
App.Person = Ember.Object.extend({
say : function(thing) {
alert(thing);
}
});
Further, under defining models section this example is given which uses DS.model
App.Person = DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
birthday: DS.attr('date'),
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
What is the difference between these three and when to use which?
Ember Data ships with four basic transform types: string , number , boolean and date . You can define your own transforms by subclassing DS.
In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.
Ember. js is an open source, free JavaScript client-side framework used for developing web applications. It allows building client side JavaScript applications by providing a complete solution which contains data management and an application flow. The original name of Ember.
As stated in this very illustrative article on Ember.Object:
Almost every object in Ember.js is derived from a common object: Ember.Object. This object is used as the basis for views, controllers, models, and even the application itself.
This simple architectural decision is responsible for much of the consistency across Ember. Because every object has been derived from the same core object, they all share some core capabilities. Every Ember object can observe the properties of other objects, bind their properties to the properties of other objects, specify and update computed properties, and much more.
Now to the differences and when you might use them depending on your use case.
Ember.CoreObject
with the Ember.Observable
mixin applied.Ember.Object
Ember.Object
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With