Jörn Zaefferer wrote:
>
> ...
> The big so far unsolved question: What should the API methods look like?
> How to pass the additional data to the event handler?
>
> Currently I favor an interface that looks like this:
> $().bind("type of event", eventHandler, {amount: 5, data:
> additionalStuff})
> $().trigger("type of event", {bubble: true, data: moreStuff});
> ...
> Your opinions?
>
I hope the event shortcuts will remain, like click( handler ) to bind and
click() to trigger.
As for the bind style, I think the handler should always be the last
argument, because to me it's cleaner this:
$( "div" ).bind( "click", {amount: 1}, function() {
doClick();
} );
than this:
$( "div" ).bind( "click", function() {
doClick();
}, {amount: 1} );
Sure having the function at the bottom makes optional arguments a little
more complitated, and if you think it's better to avoid all those type
checking in the code (I think the same) then the solution is to have no
optional arguments at all, like this:
$( "div" ).bind( "click", {}, function() {
doClick();
} );
This style adds a bit of self-documentation to the script, making it clear
that we are using default values for the second argument.
--
View this message in context:
http://www.nabble.com/jQuery-1.1-API-improvements-%28macros%2C-events%29-tf2713203.html#a7565490
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/