萌新求问promise.map与underscore.map的区别
发布于 6 年前 作者 Masterlu1998 3426 次浏览 来自 问答

在实际项目中,我发现这两个map的表面行为似乎一模一样,想问下这两个函数有什么区别吗?两个函数的使用有场合讲究吗?(注:promise引用了bluebird)

3 回复

我没用过promise的map- -,过猜一下区别应该就是underscore的map是同步函数,promise的肯定是异步呀

_.map应该就是简单的forEach封装 根据bluebird的文档 Promise.map( Iterable<any>|Promise<Iterable<any>> input, function(any item, int index, int length) mapper, [Object {concurrency: int=Infinity} options] ) -> Promise 这个就是一个支持promise的map,会自动 await promise。 根绝ECMA-262是没有Promise.map的,只有Promise.all 这个是blurbird封装的一个工具函数。

http://bluebirdjs.com/docs/api/promise.map.html

@noe132 @koroshi 感谢两位回复 我明白了!

回到顶部