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.data
property is the data passed in the .on()
call, and there is nothing passed so it returns null
. The data property you added in your call to $.Event
is overwritten by the null
. Don't use any property names mentioned here for your custom data name:
http://api.jquery.com/category/events/event-object/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With