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, 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.
It makes more sense to me this way. It is more readable with the space after the
functionkeyword (I do the same withif,while, etc) and it makes sense not to put it after the function name since you usually invoke it without a space.