bevacqua / js

:art: A JavaScript Quality Guide
https://ponyfoo.com
MIT License
2.93k stars 502 forks source link

Functions in README #1

Closed davidchase closed 10 years ago

davidchase commented 10 years ago

When declaring a function, always use the function expression form instead of function declarations.

Yet underneath you show that var foo = function(){}; is bad whilefoo function(){}; is good

I thought function expression is the storing of anonymous or named functions in a variable and function declaration is a named function without a variable assignment.

bevacqua commented 10 years ago

Function expression is an anon function, named func expr is a named function and func declaration is the var foo form

theborakompanioni commented 10 years ago

@bevacqua That is definitely not right. The "var foo form" is a function expression.

bevacqua commented 10 years ago

Should be more accurate after 6dfed021a3dfa21ddc76510aef0ab8624ca51ca9

davidchase commented 10 years ago

:thumbsup: for the fix, but i still prefer function expressions var foo = function(){} like you say always declare function on top of scope, that way your using them only after they have been created :smile:

bevacqua commented 10 years ago

Yeah, that's fine too, but using declarations you won't have to remember to put them before things that need to execute the function