7

I do PHP/Javascript development in NetBeans, and I really like the environment, except for one thing - in Javascript, when I press ENTER after a statement, and type the opening brace, it is indented. Like this:

if ( a == b )
    {}

I want the brace to stay on the same level, like this:

if ( a == b )
{}

So that when I press ENTER again, I'd get this:

if ( a == b )
{

}

Can this be done and how?

4

2 回答 2

2

对不起,我没有你的问题的答案。我也徒劳地搜索了 NetBeans 6 中的某个地方来配置 JavaScript 格式。

但是,您应该注意以下几点:
在像 Java 这样的语言中,在同一行上的左大括号和换行上的左大括号之间进行选择是合法的。然而,在 JavaScript 中,你应该坚持使用前者,因为后者会产生歧义,从而影响代码的解释。见这里。(我知道您引用的示例与if语句有关,但大概您希望保持一致。)

于 2011-05-29T14:49:11.483 回答
1

netbeans 的好消息在这里:(netbeans 7.0)

Tools -> Options > Editor > Code Templates: choose Language (Javascript in this case)

寻找“ if ”的缩写:

更改扩展文本定义:

由此:

if (${expr}){
    ${cursor}
}

对此:

if (${expr})
{
    ${cursor}
}

保存选项。

现在在一个 js 文件中输入if并按[tab] ... 你明白了...

你能想象这些模板的所有可能性吗?

于 2011-06-30T00:53:48.190 回答