Skip to content

Commit

Permalink
demo for apply.js
Browse files Browse the repository at this point in the history
  • Loading branch information
freewind committed May 17, 2012
1 parent 4a556ff commit 608c876
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var async = require('async');

var t = require('./t');
var log = t.log;

/**
* async.apply是一个非常好用的函数,可以让我们给一个函数预绑定多个参数并生成一个可直接调用的新函数,简化代码。
*
* function(callback) { t.inc(3, callback); }
* 等价于:
* async.apply(t.inc, 3);
*/
async.parallel([
async.apply(t.inc, 3),
async.apply(t.fire, 100)
], function (err, results) {
log('err: ', err);
log('results: ', results);
});

// 预设参数
var x = async.apply(t.inc, 1);
x(function(err, n){
console.log('1.inc: ' + n);
});

0 comments on commit 608c876

Please sign in to comment.