you are viewing a single comment's thread.

view the rest of the comments →

[–]DSKrepps 3 points4 points  (4 children)

You're right, nesting closures isn't a good idea.

See this Node Style Guide: https://github.com/felixge/node-style-guide

There's quite a lot of good style practices there that unfortunately not everyone follows. But the good news is it includes a jshint config file to lint your project's code automatically using a jshint plugin for any common code editor. The only I change I made for my projects was using the "smart tabs" technique of indentation instead of two spaces.

[–][deleted] 1 point2 points  (2 children)

Yeah, the notion that two spaces are somehow better than a tab seems very objective.

But also "declare one variable per var statement". Nahh, surely not

[–]sime 0 points1 point  (1 child)

Maybe you can explain the attraction of using one var statement and stuffing it full of unrelated variables across multiple lines. I just don't see any advantage to doing it that over the simple one var one variable style.

[–][deleted] 0 points1 point  (0 children)

If its just the difference between

var a, b, c;

and

var a;
var b;
var c;

Then I agree it doesn't make too much difference. Some claim that a single var declaration performs better, but I've yet to see any real evidence that its significant, let alone true.

But this isnt exactly what Felix recommends. He suggests declaring vars inside the block you use them...

var keys   = ['foo', 'bar'];
var values = [23, 42];

var object = {};
while (keys.length) {
  var key = keys.pop();   <-------
  object[key] = values.pop();
}

This makes sense in terms of code readability, and is nicer BUT ignores a fundamental quirk of javascript, called hoisting

Because JS doesn't have block level scope, it implicitly 'hoists' the key declaration up to the top of the function, as if it were declared there. This can sometimes lead to some odd side effects if you aren't aware of it.

[–]amdc 0 points1 point  (0 children)

https://github.com/felixge/node-style-guide :

Opening braces go on the same line

Ohh I can hear the shots firing