In my opinion, it depends on who else will be working with your code. If you work on a C# team and share a lot of responsibilities, put it on a new line and avoid the inevitable bickering that would otherwise follow. If you work with a lot of PHP (or older JS programmers), put it on the first line for the exact same reason.
But if you're looking for something more authoritative, Douglas Crockford says that the opening brace should always be on the top line. His reasoning, if I remember correctly, is that it makes it consistent with the rest of the language. Basically, because this is valid but (probably) incorrect code:
function myFunc()
{
return
{
ok: true
};
}
...you should universally avoid putting open-braces on a new line. Why? Because programming style should not lead to syntactic ambiguity.
The sample code above is valid because it is completely syntactically correct and no exceptions will be raised if you write this. However, instead of returning an object literal, {ok:true}
, it will return undefined
and the code below it will not be reached. Put the opening braces up one line and it will return the object literal you were, perhaps, expecting.
The question is, do you find that argument compelling enough?