When doing this:
$(document.body).on(
'myevent',
function (ev) {
console.log(ev.data, ev.result);
}
);
$(document.body).trigger(
$.Event(
'myevent',
{
data: 'foo',
result: 'bar'
}
)
);
The console returns [null, undefined]. It this something expected? I found it troubling since there is no original event to copy the properties from, and I am running out of property names to send out server response.
ref: http://api.jquery.com/trigger/
ref: http://api.jquery.com/category/events/event-object/
Note of the documents describe this behavior. If some one knows why and explain from the jQuery source code it would be great; we could file a bug if it’s something unexpected.
The
ev.dataproperty is the data passed in the.on()call, and there is nothing passed so it returnsnull. The data property you added in your call to$.Eventis overwritten by thenull. Don’t use any property names mentioned here for your custom data name:http://api.jquery.com/category/events/event-object/