Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js: OK to avoid this.get('attr')?

Tags:

ember.js

My Ember.js model, view, and controller classes are getting a bit verbose. Part of this comes from writing this.get('attr') instead of this.attr.

Is it OK to always just write this.attr, as long as the attribute is declared directly, not via a binding?

(I understand that setting is a different issue -- you always have to call this.set('attr', value) in order to update dependent attributes and templates.)

like image 434
Jo Liss Avatar asked Feb 03 '12 01:02

Jo Liss


2 Answers

IIRC, you can do this for private properties that you know will not be observable.

The convention is to prefix your private properties with an underscore (eg _myProperty) which tells Ember not to bind it.

See the docs for .get(), or check the source code if you're so inclined.

like image 172
Luis Avatar answered Oct 11 '22 22:10

Luis


If the property is being observed or bound, you DON'T want to do 'this.attr'. The get command is the nexus through which observers and bindings are triggered.

like image 42
jasonpgignac Avatar answered Oct 11 '22 20:10

jasonpgignac