Hey guys. This week the jQuery project released jQuery 1.5 which came with a number of interesting new features – one of the most significant ones was the concept of deferreds (or dfds for short) and the other was jQuery.sub(). Eric Hynds wrote a great article that explains deferreds in detail and today I’d like to explain .sub() in a short 10 minute screencast.
The basic idea behind jQuery.sub() is that it provides a relatively easy way to modify or override jQuery methods without affecting the original methods for others wishing to use them on the same page. It’s got a number of useful applications and in the screencast I’ll take you through some live examples that will (hopefully) explain them well, regardless of what level you’re at.
Watch the tutorial on how to use jQuery.sub() below (10 mins)
I recommend switching to HD mode and going fullscreen for the best viewing experience.
Watch the full-size jQuery.sub explained screencast from Addy Osmani on Vimeo
- The code used on jsFiddle.net: http://jsfiddle.net/g2txR/
- jQuery .sub() on the API site: http://api.jquery.com/jQuery.sub/
- YouTube 720p Mirror: http://www.youtube.com/watch?v=5RhZeMYssLc
- Vid.ly SD Mirror: http://vid.ly/2q3x9o/
- Blip.tv SD Mirror: http://blip.tv/file/4707329
Thanks to vladikoff and coldhead for reviewing the screencast before it went live.


awesome, will you also please go over the changes to .ajax?
Hey Theresa. I'll see what I can do!
Thanks to Jared and Yehuda for making this happen.Thanks to Jared and Yehuda for making this happen.
Whoops, i don't know how that was doubled!
Me neither, but hey, at least now we'll be twice as sure to thank Jared and Yehuda for the feature
Great explanation! Nice examples with Stewie.
Thanks! I hope it helped explain everything : )
Pingback: jQuery 1.5: jQuery.sub() Explained :DotNetInfos
Pingback: Weekend Posts & Videos For jQuery Developers (4/1/2011)
Pingback: Link-urile săptămânii 1-6 Feb 2011 « Staicu Ionuţ-Bogdan - the Frontend Developer Staicu Ionuţ-Bogdan – the Frontend Developer
Pingback: jQuery: » jQuery Community Updates For February 2011
Pingback: New Releases, Videos & A Sneak Peek At The jQuery UI Grid | Webdevelopment Resources
Where are you getting .apply? It's not in the jq docs. Cheers.
Duh…I forgot that it's a JS method
haha. It's quite alright, Greg. It happens to all of us now and then
Absolutely brilliant explanation. I love this method it will make my work a lot easier.
Thanks Matt. I'm glad the tutorial was helpful!
Cheers Addy, you provide a good explanation for this new feature! I've never seen one of your screen-casts before… loved the intro lol!
As for the usefulness of jQuery.sub() I've written two examples as a gist. One using jQuery.sub() and one without, showing how you can add methods to your plugins instance only. My current opinion is that it appears simpler not to use jQuery.sub().
I'm pretty sure I must be missing something and would appreciate any input you might have. Check out this gist: https://gist.github.com/827617
Pingback: New Releases, Videos & A Sneak Peek At The jQuery UI Grid
Pingback: New Releases, Videos & A Sneak Peek At The jQuery UI Grid | Scripting4You Blog
Is that it provides a relatively easy way to modify or override jQuery methods without affecting the original methods for others. http://www.modboxtv.com/
Very interesting this article, the tutorial was help for me.
This video is very useful and full of information. Thanks!
I agree the tutorial and I learned how to use it and Is that it provides a relatively easy way to modify or override jQuery methods without affecting the original methods for others.
Thank you,,
I’m really loving the theme/design of your weblog. Do you ever run into any browser compatibility problems? A number of my blog readers have complained about my website not operating correctly in Explorer but looks great in Opera. Do you have any suggestions to help fix this issue?