Comments (2)
The guide already has a bunch of examples on how functions should be declared, but they are given in the context of other rules. I wouldn't mind an explicit section for this.
from node-style-guide.
I almost always prefer function declarations over function expressions (see this). So...
function packAssets(...) {
return packed;
} // also, notice no semicolon, that's because it's incorrect to have one here
And I generally will put all my function declarations at the bottom of the closure to make my code more readable:
module.exports = {
packAssets: packAssets
};
function packAssets(...) {
return packed;
}
Doesn't really buy you much when you only have one function, but after about 3 or 4 it makes it a lot easier to know what the module's api is without having to scroll at all.
Function declarations also improve your stack trace because the function has a name whereas a function expression is nameless unless you explicitly give it one, which people rarely do.
These are my opinions though, curious to hear @felixge weigh in.
from node-style-guide.
Related Issues (20)
- PascalCase vs camelCase instead of UpperCamelCase vs lowerCamelCase
- ESLint: Strings must use doublequote HOT 1
- Why declare multiple var is right in node.js but wrong in javascript HOT 2
- Why 2 space indentation HOT 6
- Object.freeze HOT 2
- The .jshintrc doesn't meet your standrads HOT 2
- Push to npm HOT 7
- Rule 'space-in-brackets' was removed and replaced by: object-curly-spacing, array-bracket-spacing, computed-property-spacing
- As the name abbreviations? HOT 1
- TOC
- ESLint: space-after-keywords replaced by keyword-spacing HOT 2
- naming of files HOT 2
- Ternary operators, again HOT 2
- Closure confusion HOT 2
- else/else if on newline HOT 6
- Object / Array creation - trailing comma on last key
- Translate it to Chinese
- Early return from a function is not always a good idea. HOT 2
- node js style guide with ES6 standards. HOT 1
- statement inside curly braces should be on next line(arrow functions) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-style-guide.