-
Notifications
You must be signed in to change notification settings - Fork 33
Coding practices guide
Jérémie Astori edited this page Feb 7, 2015
·
13 revisions
- Prefer Promises over callbacks whenever possible. Promises are the future (see what I did?).
- Promises can be confusing. Read about it:
- The Promise object on MDN
- Promises by Forbes Lindesay
- Callbacks are imperative, promises are functional, by James Coglan
- You're Missing the Point of Promises, by Domenic Denicola
- When dealing with Node-style callbacks, use:
// The new readFile returns a promise rather than expecting a callback
var readFile = Promise.denodeify(require('fs').readFile);
- Do not use
eval
. -
eval
has aliases:- Do not use the
Function
constructor. - Do not pass strings to
setTimeout
orsetInterval
.
- Do not use the
- Always provide tests.
- Try to make your tests self-contained. Not doing so can result in unexpected behavior when running tests locally compared to when they are run on the CI instance.