Aaron
Aaron

Reputation: 14019

What are the attribute like names on my ember model?

I have an ember model that has two attributes defined: name and address. If I get a model from the server I can access these with myVar.get('name') or myVar.get('address') but I've noticed that I also have myVar.name and myVar.address which are both undefined. What are these and if I set up my model differently would I be able to access my attributes through them?

Upvotes: 1

Views: 108

Answers (1)

James
James

Reputation: 4737

I can't explain why you're getting undefined with the dot notation if the get method is returning defined values. But generally, it helps to consistently use get and set since Ember has computed properties, data binding and observers. Refactoring can be easier and it also supports the unknownProperty handler.

From the doc for get:

This method is usually similar to using object[keyName] or object.keyName, however it supports both computed properties and the unknownProperty handler.

Because get unifies the syntax for accessing all these kinds of properties, it can make many refactorings easier, such as replacing a simple property with a computed property, or vice versa.

From the doc for set:

This method is generally very similar to calling object[key] = value or object.key = value, except that it provides support for computed properties, the unknownProperty() method and property observers.

Upvotes: 1

Related Questions