JavaScript空间后功能 [英] JavaScript Space After Function
问题描述
当定义一个如下的函数时:
函数Foo(a,b,c){}
我没有在函数名称后面放一个空格。但是,如果我创建一个函数作为表达式:
Bar(函数(a,b,c){
//做某事
})
或
{
Foo:function(a,b,c){
//做某事
}
}
我发现自己自然地输入了一个空格。我认为这是因为我已经训练自己在函数关键字(或关键字)后立即键入一个空格。但是,根据具体情况,空间可能看起来很尴尬。更有意义的是什么?大多数人做什么?
对不起,如果以前有问题,我没有看到它。
我也是这样。
$ b $函数名称(){...}
这对我来说更有意义。在函数
关键字之后的空格更具可读性(如果, >而
等),它是有道理的,不要把它放在函数名后面,因为你通常没有空格就调用它。
I know that white space is irrelevant in JavaScript, but I am curious about style.
When defining a function like:
function Foo(a, b, c) {}
I do not put a space after the function name. But, if I am creating a function as an expression:
Bar(function (a, b, c) {
// do something
})
or
{
Foo: function (a, b, c) {
// do something
}
}
I find myself naturally typing a space. I think this is because I've trained myself to type a space immediately after the function keyword (or keywords in general). However, depending on the context, a space can look awkward. What makes more sense? what do most people do?
Sorry if this has been asked before; I didn't see it come up.
I do the same.
function () { ... }
function name() { ... }
It makes more sense to me this way. It is more readable with the space after the function
keyword (I do the same with if
, while
, etc) and it makes sense not to put it after the function name since you usually invoke it without a space.
这篇关于JavaScript空间后功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!