setUnknownProperty


#1

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){
    runMyCode()
    return;
  }
});

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;
    this.notifyPropertyChange(k);
    return v;
  }

But with no luck.


#2

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


#3

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


#4

Finally I was able to make progress with:

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

Not sure this is the best way though