chuanxshi / javascript-patterns

JavaScript Design Patterns

Home Page:http://shichuan.github.io/javascript-patterns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function declarations -- antipattern?

padolsey opened this issue · 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

+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.