5 ms·
* Comment with JSDoc style * Auto-build docs and script for development and production environemnts (easy to concatenate and then pipe this to YUI Compressor)
by erlanger 17y ago
* Comment with JSDoc style
* Auto-build docs and script for development and production environemnts (easy to concatenate and then pipe this to YUI Compressor)
* Use an MVC project organization or something like-minded. You can't just throw files representing widgets around.
* Write unit tests. JSUnit and SrewUnit (I prefer the latter) work well for this.
* Format your code nicely (this goes for any code but I find a ton of terribly formatted JS)
* Use one common library for any core object prototype changes (on Element, Array, Function, etc.) and don't modify them further.
* JSLint code you're unsure about.
* The best way to dynamically load code is just to write script tags to the document.
A few style-concerned ones...
* Don't use the module pattern. It's rarely appropriate, hiding methods does nobody good, just use a closure.
* Only create elements when absolutely necessary and destroy ones that you will no longer use. There's no garbage collector in that regard.
* Use a routing system to manipulate and read document.location.hash (and the browser history) so that pages have real URLs and navigate like webpages.
* Callbacks and delegates are great, they should be used all over the place.
* Use events and listeners to connect the parts of your app.
- mr_cheese 17y ago* For unit tests, also check out Jasmine. * +1 on not using the module pattern.
- entelarust 17y agoGreat points Just curious. For large scale projects, do you suggest building on top of existing javascript libraries (i.e. prototype, jQuery, mootools, etc)?
- mattiss 17y ago+1 for jQ
- erlanger 17y agoIf it's UI-based, I'd use ExtJS. Otherwise, MooTools. Both of these are very performant and give you a lot to work with in a neat package. jQuery UI, MochaUI, etc. are all miles behind ExtJS when it comes to behaving (reliably and efficiently) as a real tookit (with widgets and layouts). In my opinion, jQuery is suitable for progressive enhancement but not for dedicated apps.
- monos 17y agoagreed. rules on serverside are a bit different. especially the module pattern is a must there. in the future you might be able to pick one of those module loaders http://wiki.commonjs.org/wiki/CommonJS http://wiki.commonjs.org/wiki/CommonJS
- monos 17y agoalso: http://dev.opera.com/articles/view/javascript-best-practices/ http://dev.opera.com/articles/view/javascript-best-practices...
- Tichy 17y agoUnfortunately they recommend the bad variant of hungarian notation. Bad, bad, bad :-(
- wolfhumble 17y agoWhich variant of hungarian notation do you prefer?
- nex3 17y agoSee http://www.joelonsoftware.com/articles/Wrong.html http://www.joelonsoftware.com/articles/Wrong.html, particularly the section "I'm Hungary", for a comparison between two different styles of Hungarian notation.
- wolfhumble 17y agoI remember having read that before; will take a new look and implement the good parts in my code. Thanks!
- z8000 17y agoThe none kind.