-
-
Save makeusabrew/4451255 to your computer and use it in GitHub Desktop.
// 1) colon aligned, no spaces where possible | |
var Foo = { | |
host :"foo", | |
db :"bar", | |
details:"baz" | |
}; | |
// 2) colon aligned, space after key | |
var Foo = { | |
host : "foo", | |
db : "bar", | |
details: "baz" | |
}; | |
// 3) colon aligned, space before & after key | |
var Foo = { | |
host : "foo", | |
db : "bar", | |
details : "baz" | |
}; | |
// 4) space aligned, no spaces where possible | |
var Foo = { | |
host: "foo", | |
db: "bar", | |
details:"baz" | |
}; | |
// 5) space aligned, space after key | |
var Foo = { | |
host: "foo", | |
db: "bar", | |
details: "baz" | |
}; | |
// 6) space aligned, space before & after key | |
var Foo = { | |
host : "foo", | |
db : "bar", | |
details : "baz" | |
}; | |
// or something else entirely? |
Ah cool, thanks for the tip @mheap.
#5 without alignment fits nicely and consistently with 1 line definitions too, e.g.
var Foo = { host: "foo", db: "bar" };
var Foo = {
host: "foo",
db: "bar",
details: "baz"
};
Believe it or not I was going to list various other options without indentation (such as @stephenmelrose's variation of #5) but thought I'd get burnt at the stake for even suggesting such a thing. Good to know :)
#5 but without alignment, same as @stephenmelrose
I'm with @stephenmelrose
@makeusabrew I think comma-first would have got you burnt at the stake :)
Same as steve for this, the real question is where to put the newlines and how much to indent when passing an object literal as a function argument!
@davedevelopment Ewww.
Wow, this is 4-year-old thread. But this how I align things.
Right align keys on colon. Values left aligned with space after colon.
{
key: 1,
string: "value",
object_key: {
string_key: "string",
integer_key: 2
},
function_key: () => {
}
}
#5 for me, but I occasionally slip in to the same as stephenmelrose