When you first come to Ember, you’ll soon stumble upon three things:
For some people (including me) it is not very clear what’s the difference between the first two.
Ember.Controller is just a plain implementation of
Ember.ObjectController is a subclass of
Ember.ObjectProxy. This is a huge difference! Let’s take a look at how
Ember.ObjectProxy works, and as always starting with a code sample
(taken from the excellent source code documentation).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
There is really no magic. In the basic usage,
delegate all of it’s unknown properties to the
content object, with
If we try to set a new property on a proxy while it’s content is undefined, we will get an exception.
I’ve stumbled upon this in one scenario, where I didn’t set content for
ObjectController, but I tried to modify one of it’s properties.
Raising the exception is a good example of failing fast, rather than
silently swallowing errors.
This being said you should almost always use
Ember.Controller, unless you know what you’re doing :)