O'Reilly logo

Mastering Ember.js by Mitchel Kelonye

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining computed properties

What is a computed property? A computed property is the one whose value is returned from a function. For example:

var Movie = Ember.Object.extend({
  name: function(){
    return 'Transformers';
  }.property()
});

var movie = Movie.create();
console.log(movie.get('name')); // Transformers

The preceding example creates a computed property name that returns the name of a movie instance.

We simply transformed a method into a computed property by chaining the property() function to it. The true power of computed properties comes from them being able to produce different values based on prespecified dependent properties. These dependent properties are usually passed as arguments to the property() function. For example:

var Movie = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required