Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
@erikrose's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed May 16, 2014
1 parent fb74dc2 commit 3ffad96
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion js-style.rst
Expand Up @@ -134,7 +134,36 @@ Functions
Named Functions
~~~~~~~~~~~~~~~

Not necessary.
There's no need to explicitly name a function when you're already
assigning it to a descriptively named symbol:

::

var updateOnClick = function() { ... };

...or...

::

var someObejct = {updateOnClick: function() { ... }

Most modern JS engines will infer the name updateOnClick for the above
anonymous function and use it in tracebacks.

Of course, if you're passing a nontrivial function as an argument, you
should still contrive to name it somehow. The meaning here would be
needlessly obscured if the anonymous function were 10+ lines long:

::

.forEach(function() { ... })

In such cases, either name the function, or pass a descriptively named
symbol that points to a function.


Whitespacing Functions
~~~~~~~~~~~~~~~~~~~~~~

No space between name and opening paren. Space between closing paren and brace::

Expand Down

0 comments on commit 3ffad96

Please sign in to comment.