Skip to content
This repository

Trivial issue #2

Open
JeffreyM opened this Issue March 30, 2011 · 6 comments

4 participants

JeffreyM Felix Geisendörfer Morris Johns Michael Wiesendanger
JeffreyM

Hey Felix - thanks for the effort you put into the style guide.

Under Array/Object Creation you'll find a trailing comma..

var a = ['hello', 'world'];
var b = {
good: 'code',
'is generally': 'pretty',
};

Felix Geisendörfer
Owner

That one is actually on purpose, since it's perfectly acceptable in v8 / ecma5 and the document clarifies that as the only target plattform initially. Maybe I should add an additional note there so?

Morris Johns

Surely many node programmers also program for browsers, so unless a style difference is important, choosing a style that works for both node and browsers would be good... or if you are suggesting the trailing comma is a recommended style, then perhaps it needs its own section?

The only other section that personally felt a bit queezy was "Feel free to give your closures a name", which is only problematic for obsolete browsers... hurrah for sticking one up them!

Basically I have to agree with everything (even trailing commas and named closures), so any gripes I might have are just showing my envy! Thanks heaps.

Felix Geisendörfer
Owner

Surely many node programmers also program for browsers, so unless a style difference is important, choosing a style that works for both node and browsers would be good... or if you are suggesting the trailing comma is a recommended style, then perhaps it needs its own section?

Trailing commas are recommended. I will add more information on this if I get a chance.

The only other section that personally felt a bit queezy was "Feel free to give your closures a name", which is only problematic for obsolete browsers... hurrah for sticking one up them!

If you are leaking closures, naming them will let you discover them with v8's heap profiler. You'll also get more meaningful exceptions. And you may also create more readable code. YMMV.

Michael Wiesendanger

Hi just stumbled about the same thing and wanted to open a bug because of the trailing comma. Would be really interested in your clarification because for me this is at least bad practise.

Felix Geisendörfer
Owner

@playerwtf it makes editing code easier as the rule for removing or adding a line is always the same, regardless of the position it has in the list of lines. Treating the last line special by omitting the comma is a bad practice IMO.

Michael Wiesendanger

@felixge you seem to have a valid point. But it just looks so ugly :). I think I read about it the first time in Douglas Crockfords Book 'Javascript: The God Parts' and followed it since then. But I also remember that I did this mainly because of the lack of ie8, that failed when you had a trailling comma like this.

But as you stated above you clearly noted that this document targets ecma5/v8.
Anyway thanks for your effort you put into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.