Javascript Space After Function
Solution 1:
I do the same.
function () { ... }
functionname() { ... }
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.
Solution 2:
It is matter of personal preference. No doubt proper spacing does aid to readability which is always a good idea.
The important thing though when it comes to JavaScript coding style, is to always put starting curly brace on the same (due to automatic semi-colon insertion) line unlike:
functionmyFunc()
{
return
{
name: 'Jane'
};
}
var f = myFunc();
console.log(f); // undefined
Read More:
Solution 3:
I agree, when coding Javascript i want my code to be as readable as possible and I've gotten to find that having a whitespace to separate the the keyword ease the reading, for me.
Solution 4:
My suggestion:
If the ()
is the function invocation operator, don't put a space before it. In all other cases do put a space before it.
functionf ( x ) {
// ...
}
var g = function ( y ) {
// ...
};
f( 1 );
g( 2 );
That way, you can identify invocation operators more easily.
Post a Comment for "Javascript Space After Function"