How can i achieve this?
$(window).bind('done', function (e) {
e.result = "my data";
});
var state = $(window).trigger('done');
equal("my data", state);
Currently .trigger returns the JQuery object.
UPDATE
Event is triggered from another module, so i can’t use closures.
You have to appreciate that event handlers are asynchronous in JavaScript. This implies that a call to an asynchronous function has no output, no return value. The only way to get data from an asynchronous function is by passing in a callback that will be called whenever the output is available – or when the event that you’re waiting on has occurred.
jQuery has a rather elegant
deferredAPI for this. I’m not how it works together with event handlers as I don’t use jQuery very much but I guess that is what you should be going for, rather than this .. abomination.