javascript-patterns icon indicating copy to clipboard operation
javascript-patterns copied to clipboard

Function declarations -- antipattern?

Open padolsey opened this issue 12 years ago • 2 comments

Here you mention that function declarations are an anti-pattern. However you don't substantiate this. Do you say this because FunctionDeclaration hoisting is sometimes considered confusing?

I don't believe Function Declarations are an anti-pattern at all. In fact they're favourable in many cases --

  1. for debuggability
  2. for semantics
  3. sometimes hoisting is useful (declaring static constants above a FuncDec

padolsey avatar Mar 18 '13 11:03 padolsey

+1

nickdesaulniers avatar Jan 03 '14 05:01 nickdesaulniers

+1

I cannot agree that function declaration is an anti-pattern. I even prefer it over the other possibilities because it clearly says that I define a function.

Moreover, it's extremely popular in node source code and in many successful libraries where people really care about code quality.

adambabik avatar Jan 03 '14 19:01 adambabik