what's the node standard way of manage callbacks
发布于 9 年前 作者 boyishwei 3410 次浏览 最后一次编辑是 8 年前 来自 问答

what’s the node standard way of manage callbacks?

今天在使用connect-rest module的时候看到这段demo代码有点不解,

rest.get('/handlers/buffer', function( request, content, callback ){
	...
	...
	...
    return callback(null, new Buffer( 'ok', 'utf-8') );
});

这里的 callback 是 connect-rest 这个 module 封装好的?不然哪里传进来的? 正常的callback不是在异步后被轮训到的时候被调用,这里仅仅是传递了一个方法进来,然后显示的执行了这个方法,并且反回,取个名叫callback,让人费解。 还有正常的express function都是带有request,response等参数, connect-rest 在这里把response省了, 然用使用了一个callback,这样实现有什么好处?

另外在看 doc 的时候看到了这样一句话: an optional callback function. This is the ‘node standard’ way to manage callbacks if needed. What’s the node standard way of callback management exactly??? Can some one help me to address this?

回到顶部