I spent past week on a jQuery implementation. And retrospectively, though I know how to code, I have to admit I do not know how to organize my code.
There are lots of tutorials explaining how to perform one single operation with jQuery, but what I lack is best practices. The design patterns I use in PHP do not handle concepts such as asynchronous and behaviors. I don’t know how to handle the non-linear timeline.
Thus, my jQuery / javascript code gets invariably messy.
Can you give me advice on what to read to remedy this problem ? Books, tutos, etc. are welcome.
Thanks in advance !
A good way to organize code is developing with common javascript
patterns: an interesting overview by Addy Osmani can be found here: http://addyosmani.com/resources/essentialjsdesignpatterns/book/ .If one of your biggest problem is to deal with asynchronous task, jQuery offers an implementation of
Promises/Apattern provided byDeferred objectssince version 1.5, so try to take a look at the online reference (see http://api.jquery.com/category/deferred-object/)If you’re also looking how to organize jQuery code in a plugin then I also suggest this resource: http://jqueryboilerplate.com/