mkemper
mkemper

Reputation: 3

Computed properties example in ember.js fails

I'm trying to learn emberjs and stumbled over an error in the example of the computed properties section (www.emberjs.com, 'Computed properties in action' example in the 'guides'section). It always shows the error "Property 'fullName' of object [object Object] is not a function" when I call ironMan.fullName() from the console of the browser - Why is that?

My code is:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0-rc.3/handlebars.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ember.js/1.0.0-rc.6/ember.min.js"></script>
<script>
App = Ember.Application.create();

App.Person = Ember.Object.extend({
  // these will be supplied by `create`
  firstName: null,
  lastName: null,

  fullName: function() {
    return this.get('firstName') + ' ' + this.get('lastName');
  }.property('firstName', 'lastName')
});

var ironMan = App.Person.create({
  firstName: "Tony",
  lastName:  "Stark"
});
</script>

Also in a jsbin: http://jsbin.com/UnevOVU/3/edit

Upvotes: 0

Views: 69

Answers (1)

Trek Glowacki
Trek Glowacki

Reputation: 3621

This error is telling you that ironMan.fullName is not a function and cannot be called with (). This is because fullName is a computed property object, not a function. You can access its value with the code shown directly below this code sample in the guide:

ironMan.get('fullName') // "Tony Stark"

Upvotes: 1

Related Questions