get (keyName) Object
public
Retrieves the value of a property from the object.
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.
Computed Properties
Computed properties are methods defined with the property
modifier declared at the end, such as:
fullName: function() { return this.get('firstName') + ' ' + this.get('lastName'); }.property('firstName', 'lastName')
When you call get
on a computed property, the function will be called and the return value will be returned instead of the function itself.
Unknown Properties
Likewise, if you try to call get
on a property whose value is undefined
, the unknownProperty()
method will be called on the object. If this method returns any value other than undefined
, it will be returned instead. This allows you to implement "virtual" properties that are not defined upfront.
Parameters:
-
keyName
String
- The property to retrieve
Returns:
-
Object
- The property value or undefined.
Please login to continue.