カスタムイベントの引数を設定する方法を理解しようとしています。イベントをサブスクライブするときに引数を設定し、イベントをトリガーするときに追加のデータを追加する方法。
テスト用の単純な JS がありますが、「ハンドル」の e パラメータには、サブスクライブのデータしか表示されません。
function handle(e) {
//e.data has only "b"
alert(e.data);
}
function myObj() {
this.raise = function () {
//Trigger
$(this).trigger("custom", { a: "a" });
}
}
var inst = new myObj();
//Subscribe
$(inst).bind("custom", { b: "b" }, handle);
inst.raise();
ありがとうございました。