Tony
Tony

Reputation: 12695

VS 2010 Is possible to turn off collapsing JS code?

in VS 2010 Ultimate if You type a JS code an then press Enter, You'll notice that the 1st bracket is in the same line as e.g function header. How to turn it off ? It is very annoying for me

after pressed enter... =>

function a() { 
}

I want it as:

function a() 
{ 
}

Upvotes: 0

Views: 114

Answers (2)

Pero P.
Pero P.

Reputation: 26992

Code convention aside, the option is there in Visual Studio 2010 (Premium in my case)

Tools > Options > Text Editor > JScript > Formatting > Place open brace on new line for functions [check]

Upvotes: 0

cdhowie
cdhowie

Reputation: 169133

Using braces on the same line as the function declaration is proper JavaScript coding style (see Crockford). Using braces on the same line as the opening block is recommended due to the way JavaScript inserts semicolons wherever possible. Take, for example, this code:

return
{
    hello: "world"
};

JavaScript parsers will rewrite this as:

return;
{
    hello: "world"
};

This has a substantially different meaning, and there is no warning to the developer that this has happened, other than incorrect behavior from their script. While function declarations are ok, since function foo(); is not valid JavaScript, and parsers will therefore not insert a semicolon there, such formatting is still strongly discouraged.

If you still want to do this, you can alter this setting: Tools - Options - Text Editor - JScript - Formatting - Place open brace on new line for functions.

Upvotes: 1

Related Questions