Function Call Spacing

Almost universally, the recommended style for function calls is to have no space between
the function name and the opening parenthesis, which is done to differentiate it
from a block statement. For example:




// Good
doSomething(item);

// Bad: Looks like a block statement
doSomething (item);
// Block statement for comparison
while (item) {
// do something
}

Crockford’s Code Conventions explicitly calls this out. The Dojo Style Guide, Sprout-
Core Style Guide, and Google JavaScript Style Guide implicitly recommend this style
through code examples.
The jQuery Core Style Guide further specifies that an extra space should be included
after the opening parenthesis and before the closing parenthesis, such as:

// jQuery-style
doSomething( item );

The intent here is to make the arguments easier to read. The jQuery Core Style
Guide also lists some exceptions to this style, specifically relating to functions that are
passed a single argument that is an object literal, array literal, function expression, or
string. So the following examples are all still considered valid:

// jQuery exceptions
doSomething(function() {});
doSomething({ item: item });
doSomething([ item ]);
doSomething("Hi!");

Generally speaking, styles with more than one exception are not good, because they
can be confusing to developers.