# Is there something odd about getters and setters?

**URL:** <https://discuss.emberjs.com/t/is-there-something-odd-about-getters-and-setters/7424>\
**Category:** Uncategorized\
**Created:** [February 27, 2015, 5:20pm UTC](https://discuss.emberjs.com/t/is-there-something-odd-about-getters-and-setters/7424 "2015-02-27T17:20:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bailey86](https://avatars.discourse-cdn.com/v4/letter/b/ecccb3/32.png) [@bailey86](https://discuss.emberjs.com/u/bailey86)\
**Post date:** [February 27, 2015, 5:20pm UTC](https://discuss.emberjs.com/t/is-there-something-odd-about-getters-and-setters/7424/1 "2015-02-27T17:20:22Z")

</div>

Is there something odd about getters and setters?

This article:

> **[Ember.js is driving me crazy](http://softwaresimply.blogspot.com/2014/01/emberjs-is-driving-me-crazy.html)**
>
> For the past few months I've been working on a project with a fairly complex interactive web interface. This required me to venture into t...

seems to highlight a problem with getters and setters - is there something here that Ember newbies should be aware of?

Cheers,

Kevin

---

<div class="post-metadata">

**Author:** ![mikegrassotti](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mikegrassotti/32/14281_2.png) [@mikegrassotti](https://discuss.emberjs.com/u/mikegrassotti)\
**Post date:** [February 28, 2015, 4:32pm UTC](https://discuss.emberjs.com/t/is-there-something-odd-about-getters-and-setters/7424/2 "2015-02-28T16:32:17Z")

</div>

TLDR: Not really.

Getters and setters in ember work like you’d expect. That said, when you call get/set (or any method) on an object you should understand what that object is and refer to it’s documentation if it doesn’t behave as expected.

In the article you referenced the poster was created an [Ember.ObjectController](http://emberjs.com/api/classes/Ember.ObjectController.html) and was surprised by how get/set worked. The whole point of using an `ObjectController` instead of a `Controller` is to have this special get/set behavior. This isn’t specific to `Ember` it’s how any `ObjectProxy` works. Here’s the first line of it’s API doc:

> Ember.ObjectController is part of Ember’s Controller layer. It is intended to wrap a single object, proxying unhandled attempts to get and set to the underlying model object

I guess the lesson is don’t randomly use an `ObjectController` (or any other object) without a basic understanding of what it is for.

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [February 28, 2015, 8:17pm UTC](https://discuss.emberjs.com/t/is-there-something-odd-about-getters-and-setters/7424/3 "2015-02-28T20:17:43Z")

</div>

> [@bailey86](#):
>
> Is there something odd about getters and setters?

I am almost certain there is an observer somewhere changing the value. Might not be even in the code this person is managing, perhaps he’s passing it into a component which is observing and setting the value.

I seldom use the observer pattern, this is a good example of why. This isn’t a problem with Ember, it’s a problem with the observer pattern in general.

> Maybe a week later I ran into another problem. Some data was changing when I didn’t expect it to. I looked everywhere I could think of that might affect the data, but couldn’t find anything. Again, I spent the better part of a day trying to track down the source of this problem. After awhile I was getting desperate, so I started putting print statements all over the place. I discovered that the data was changing in one particular function. I examined it carefully but couldn’t find any hint of this data being impacted. Eventually I isolated the problem to the following snippet:

> console.log(this.get(‘foo’)); this.set(‘bar’, …); console.log(this.get(‘foo’));

> The first log line showed foo with a value of 25. The second log line showed foo with a value of 0. This is utter madness!
