felixge / node-style-guide

A guide for styling your node.js / JavaScript code. Fork & adjust to your taste.
5k stars 915 forks source link

Closure confusion #90

Open oreliable opened 8 years ago

oreliable commented 8 years ago

Use closures, but don't nest them.

https://github.com/felixge/node-style-guide#no-nested-closures

This is a little funny considering the whole point of closures is to nest them so they close over variables in their parent scope.

The examples provided are just.. regular functions.

robbiesmith79 commented 8 years ago

I see the point trying to be made. The point of a function is so that it can be reused as often as possible. Extracting the function to be by itself allows you to write less code and enhances the notion that the single point of failure is easier obtained. Also, that you can a more controlling perspective if you have to change it. Better off, in this case, you adjust the function to accept any string, so the callback just sends a string to be consoled.

krystianity commented 7 years ago

If you are not working with Promises or Chains

Use closures, but don't nest them.

is probably the only chance to prevent "Callback Hell"