Using get(this, "prop") in all situations, or only for non Ember.Object objects?


#1

Strong conventions help reduce heterogeneity and guesswork on the part of the programmer. I’ve found myself wondering whether to go with this.get("prop"); or get(this, "prop"); ever since coming across Ember.get.

Now, I understand that when dealing with simple objects, it makes sense to use get(pojo, "prop"); in case the object isn’t an instance of Ember.Object. But, when accessing properties of the controller, router or component, I know that using this.get() will always work, but I still find myself opting for Ember.get in order to maintain some design consistency.

Does the core team have any preference, or an idea whether future versions of ember will always require us to use Ember.get?


#2

FWIW, it isn’t about “simple objects” its more about “foreign objects”. They could be a POJO, some sort of native class instance, or any number of other things.

As of Ember 3.1.0 you already do not need this.get or get(this in most situations (assuming that your object is not acting like a proxy). This means that you would normally be able to do the standard JavaScript thing:

let { prop } = this;

:scream_cat: :blush:

Now, for the other cases you should use Ember.get:

  • you are not operating on this (and therefore do not know if the object is a proxy or even an Ember.Object)
  • this is an object with unknownProperty defined (aka a “proxy”)