Live data from Hacker News

Ask HN: Javascript best practices?

news.ycombinator.com

31–40 of 52 posts

Re: Ask HN: Javascript best practices?

#31
post #14

Earlier quoted context omitted.

Any tool suggestions for the job of minifying and deployment?

http://developer.yahoo.com/yui/compressor/

+1 for YUI

+2 Grok Douglas Crockford's DOM theory then optimize how your scripts use the DOM, it is very easy to abuse the DOM, don't. Grok the DOM.

Re: Ask HN: Javascript best practices?

#33

* 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…

Great points Just curious. For large scale projects, do you suggest building on top of existing javascript libraries (i.e. prototype, jQuery, mootools, etc)?

+1 for jQ

Re: Ask HN: Javascript best practices?

#34

Obfuscate variable and function names with junk words. On Windows, Jasob was easily the best http://www.jasob.com/ for it (I tried using many others including online offerings). You need to do this if worried about others seeing and using your code, especially competitors. edit: am I stupid? But when you obfuscate, you also radically shorten the length of a JS file, thus making it quicker to download: EG: function c(…

You are talking about minifying, which is great for bandwidth reduction and I suppose obfuscation.

However this post was about JS design principles.

Re: Ask HN: Javascript best practices?

#37

* 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…

agreed.

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

Re: Ask HN: Javascript best practices?

#38
post #36

When I hear "best practices" I reach for my Giant Spiked Club of Holy Wrath.

Why? What's so terrible about finding out about how those more experienced than yourself do things? I'm assuming, of course, that sound reasoning is supporting the practice rather than simple cargo culting.

Re: Ask HN: Javascript best practices?

#40

* 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…

also:

http://dev.opera.com/articles/view/javascript-best-practices...

Post reply on HN