これが実装です:http://jsfiddle.net/Sly7/GMwCu/
App = Ember.Application.create();
App.WatchedObject = Ember.Object.extend({
firstProp: null,
secondProp: "bar",
init: function(){
this._super();
var self = this;
Ember.keys(this).forEach(function(key){
if(Ember.typeOf(self.get(key)) !== 'function'){
self.addObserver(key, function(){
console.log(self.get(key));
});
}
});
}
});
App.watched = App.WatchedObject.create({
firstProp:"foo",
plop: function(){},
thirdProp: 'far'
});
App.watched.set('firstProp', 'trigObserver');
App.watched.set('secondProp', 'doesNotTrigObserver');
App.watched.set('thirdProp', 'alsoTrigObserver');
</p>
ご覧のとおり、関数ではなくプロパティのみを処理します (それが必要だと思います)。また、メソッドに渡されたプロパティに対してのみ機能し、クラス定義で指定されたもの (つまり、を使用)
に対して機能しないことも理解できます。create()
extend