Is this:
($.fn.myFunc = function() {
var Dennis = function() { /*code */ }
$('#Element').click(Dennis);
})();
equivalent to:
($.fn.myFunc = function() {
$('#Element').click(function() { /*code */ });
})();
If not, can someone please explain the difference, and suggest the better route to take for both performance, function reuse and clarity of reading.
Thanks!
The only difference is that the former provides a reference to the function.
Thus, you can do this:
Which isn’t possible with the latter.
This can be useful. For example, I may want the click to manipulate part of the page, but I also want to do it on page load. I could do so with:
(Aside: You wouldn’t call
$("#Element").click();to accomplish this unless you wanted ALL the click handlers on#Elementto fire.)