Coder Social home page Coder Social logo

declare functions about node-style-guide HOT 2 OPEN

thepian avatar thepian commented on September 18, 2024
declare functions

from node-style-guide.

Comments (2)

felixge avatar felixge commented on September 18, 2024 1

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.

kentcdodds avatar kentcdodds commented on September 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.