Comments on: Function’less event handlers in jQuery https://j11y.io/javascript/functionless-event-handlers-in-jquery/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: James https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-889 Fri, 08 May 2009 08:42:42 +0000 https://j11y.io/?p=792#comment-889 @Benson Wong, yes, this is a shortcut; no extra functionality is available. The point in the extension is to simplify the process of adding primitive event handlers. Like everything, the effectiveness of the extension is subjective – I for one do see the benefits and I think it improves readability and rids the code of unnecessary bloat.

@Paul, I know what you mean and I feel the same way while using it; I like having low-level control, especially when it comes to callbacks. The extension is just additional layer of simplicity for those who want it.

@Balazs, Thanks for your comment. I think adding any more functionality (like specifying execution order with arrays) would pretty much dispel the need for the extension in the first place; if someone needs to use ‘find’ or other methods of that type then they should definitely stick to using a callback function. Btw, that upcoming change looks promising; definitely a useful addition!

@Marko Simic, maybe you could expand your argument?

]]>
By: Marko Simic https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-888 Thu, 07 May 2009 22:53:17 +0000 https://j11y.io/?p=792#comment-888 This smells on Perl.
I am in Perl last few days and main problem is its dirtiness.
Anyway this is “nice to know”, but I would not recommend anyone to use this.

]]>
By: Balazs Endresz https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-887 Thu, 07 May 2009 22:10:01 +0000 https://j11y.io/?p=792#comment-887 I just can’t keep starring your posts lately, this is really great!

After a bit digging I’ve found the original discussion where this thing came up, there were some other interesting solutions for this:
http://groups.google.com/group/jquery-dev/msg/727536a1f11c5921
http://groups.google.com/group/jquery-dev/msg/6611968e3dfde574
http://groups.google.com/group/jquery-dev/msg/c0a13ce5067ab784

But I think yours pretty much beats beats them, the only problem I think is that you can’t specify the order of execution of the commands, so you can’t use `find` or anything that relies on it. A simple solution would be if you could (optionally) wrap the objects in an array, though it might be a bit overkill.

And watch out for the next release as it looks like there will be some important changes in the event handling code: http://dev.jquery.com/changeset/6344

]]>
By: losted https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-886 Thu, 07 May 2009 19:00:09 +0000 https://j11y.io/?p=792#comment-886 I Hope this will be implemented in some kind of way in future release of JQuery. Good work James!

]]>
By: Paul https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-885 Thu, 07 May 2009 18:37:02 +0000 https://j11y.io/?p=792#comment-885 Really nice concept. There are many cases which this would be useful. I’d like to see this implemented along with the current event functions.

My only reservation is that it feels like it breaks some of the basic concepts of jQuery. On of the big rules is that you don’t pass functions to be called in as strings. But since this rule is broken for event type, maybe this would just work along side it.

Keep up the great work!

]]>
By: ignite https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-884 Thu, 07 May 2009 16:13:05 +0000 https://j11y.io/?p=792#comment-884 Very interesting post. I hadn’t seen the “ultra chaining” discussion and I agree with the issues you’ve pointed out. I think you’re alternative method is pretty darn sweet. I like the fact that if you want to pass the typical callback function you can. Your method certainly cleans up the code a bit and makes it more structured, which is awesome.

]]>
By: JDStraughan https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-883 Thu, 07 May 2009 15:53:43 +0000 https://j11y.io/?p=792#comment-883 This is great. Added to tutlist.com

]]>
By: Benson Wong https://j11y.io/javascript/functionless-event-handlers-in-jquery/#comment-882 Thu, 07 May 2009 15:10:51 +0000 https://j11y.io/?p=792#comment-882 I’ve only been using jQuery for about 4 months, and mostly only on my twitter project, tweetlens.com. So I’m not really a JS pro (yet) 🙂

Anyways, I looked through your JS code a bit, this is really just short cut on top regular jQuery and passing anonymous functions.

So this:

$('a').bind('click.namespace', {
    addClass: 'clicked',
    animate: [{fontSize: '+=2px'}, 300]
});

instead of:

$('a').bind('click.namespace',function(e) {
$(this).addClass('clicked').animate({fontsize:'+=2px'},300)});

I don’t really see the advantages, readability isn’t even really that improved. IMHO.

]]>