I’m trying to run some code whenever a new property is set on an object. I tried:

var MyObject = Ember.Object.extend({
  setUnknownProperty: function(k,v){

I relayed on this doc for Object.set:

If setUnknownProperty() returns undefined, then set() will simply set the value on the object

But it didn’t! If I remove setUnknownProperty method, the property is set, but with it it just doesn’t. I also tried:

  setUnknownProperty: function(k,v){
    this[k] = v;
    return v;

But with no luck.


what happens if you Ember.set(this, k, v); instead of this[k] = v;?


Thanks for the answer! However, I get a stack overflow… which makes sense I guess


Finally I was able to make progress with:

setUnknownProperty: function(k,v){
  Ember.defineProperty(this, k, null, v);

Not sure this is the best way though