In Ember, defining a property as a computed alias to another property (or another object's property) using Ember.computed.alias('otherProperty')
seems to have basically the same result as defining it as a binding to that property using propertyNameBinding: 'otherProperty'
.
I've looked at the source and the documentation but I can't find any reason why one would be preferred over the other. Obviously templates use bindings, which is fine, but for properties in e.g. controllers, or for referencing a controller's property on a view, is there a difference?
An alias can be overwritten on extend(), completely eliminating the relationship with the other key.
A brief example: I have a class of time-related functions and classes, and the classes have both a unit
property (for Day, Minute, etc) and a precision
property. Normally these are functionally identical. In one or two classes they diverge. Ember.computed.alias
allows precision
to alias to unit
for most cases, but to be overridden with its own value as needed.
Note that create() will use the alias setter, instead of overriding.
Also, setting an alias with a null object in its path can blow up, while a binding will simply not sync if the path doesn't lead anywhere.
Please see morgoth's comment below per soft-deprecation of *Binding syntax
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