Note that there are some explanatory texts on larger screens.

plurals
  1. POAbout Node's code style
    text
    copied!<p><strong>EDIT</strong></p> <p>thx to all the answers, <br/> and finally I decide to use some tools like <a href="https://github.com/creationix/step" rel="nofollow">Step</a>, <br/></p> <p>all I need is "flow control" and don't want any thing else which may slow down the performance (I don't know how much exactly it would effect or the effect just can be ignored).</p> <p>So I just create a little tool for flow control:</p> <p>line.js</p> <pre><code>/** * Create the "next" function * * @param {Array} tasks * @param {Number} index * @param {Number} last */ var next = function(tasks, index, last) { if (index == last) { return tasks[index + 1]; } else { return function(data) { var nextIndex = index + 1; tasks[nextIndex](next(tasks, nextIndex, last), data); }; } }; /** * Invoke functions in line. */ module.exports = function() { var tasks = arguments, last = tasks.length - 2; tasks[0](next(tasks, 0, last)); }; </code></pre> <p>usage:</p> <pre><code>var line = require("line.js"); line(function(next) { someObj.find(function(err, docs) { // codes next(docs); }); }, function(next, docs) { // codes }); </code></pre> <p>Hope this helps.</p> <p><strong>EDIT END</strong></p> <p><br/></p> <p>As all know,<br/> Node's built-in or third-part modules often provides async API,<br/> and using "callback" function for dealing the results.</p> <p>It's cool but sometimes would code like this:</p> <pre><code> //some codes } } } } </code></pre> <p>codes like this are hard to read.</p> <p>I know "deferred" library can solve such problem, <br/> Is there any good "deferred" module for Node?<br/> And How is the performance if I code Node with "deferred"?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload