One of the problems with your first method is that you also trigger any other click events that are bound to this control; you can solve this with namespaces
$('#link').bind('click.mynamespace', function(){ ... }); $('#link').trigger('click.mynamespace');
or using the second event
$('#link').bind('do_stuff', function(){ ... }); $('#link').click(function() { $(this).trigger('do_stuff'); });
However, I would go for the second one, because it is easier if you have access to a function where you need to call it. You do not need an additional functional shell, BTW:
function do_stuff(event) { ... } $('#link').click(do_stuff); do_stuff();
If it is useful to define a function in the closure that you no longer have access to, go to the first path.
Rup
source share