私は理解しようとしていますObject.getNotifier(object).performChange
。概念的には、「マクロ」以上の変更を定義するために設計されていることを理解しています。例から、誰もが参照しているようです:
increment: function(amount) {
var notifier = Object.getNotifier(this);
notifier.performChange(Thingy.INCREMENT, function() {
this.a += amount;
this.b += amount;
}, this);
notifier.notify({
object: this,
type: Thingy.INCREMENT,
incremented: amount
});
}
私が理解していないのはnotifier.performChange
、コールバックとしてではなく、直接渡された匿名関数を単に実行することとどう違うのですか? つまり、以下とどのように違うのでしょうか。
increment: function(amount) {
var notifier = Object.getNotifier(this);
this.a += amount;
this.b += amount;
notifier.notify({
object: this,
type: Thingy.INCREMENT,
incremented: amount
});
}
最新の仕様でnotifier.performChange
は、次のように通知として発行されるオブジェクトを返す可能性があることを確認しました。
notifier.performChange(Thing.INCREMENT, function() {
this.a += amount;
this.b += amount;
// a notification is issues with this return value,
// including the type passed to notifier.performChange,
// and the object underlying notifier.
return {incremented: amount};
});
これにより、元のコードでは次の必要がなくなりますnotifier.notify
が、それでも、これは砂糖以外のものですか、それとも、変更を加えて自分で通知を発行することとの間に機能的な違いはありますか?