I’m trying to figure out, how I can set arguments for custom events.
How I can set an argument when I subscribing the event and then add some additional data when I trigger event.
I have a simple JS for testing, but in e parameter of "handle" I see only data of subscribe.
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();
Parameters supplied to
.trigger()are passed as the second parameter of the event handler function.