3 ms·
A lot of people use notation #1 to do namespacing by using objects, eg var MyProject = {}; MyProject.func = function() {} If you ever want to assign a fun
by dkyc 12y ago
A lot of people use notation #1 to do namespacing by using objects, eg
var MyProject = {};
MyProject.func = function() {}
If you ever want to assign a function to an object, you might as well do it with global-scope functions. Most debuggers/profilers I am aware of can handle this notation well. If they don't, there is still the possibility of doing
var Box = function Box (a, b) {}
The function does not have to be anonymous!
- ShellfishMeme 12y ago+1 for the named function expression. I really don't like pure function statements because of hoisting. You often end up seeing functions being used before they're defined which can lead to confusing bugs and hurts readability. I also like that `var Box = function Box (a, b) {}` directly shows people who are new to JS that function declarations are nothing else than just assigning a function to a variable.