在实际项目中,我发现这两个map的表面行为似乎一模一样,想问下这两个函数有什么区别吗?两个函数的使用有场合讲究吗?(注:promise引用了bluebird)
回复 (3)
K
我没用过promise的map- -,过猜一下区别应该就是underscore的map是同步函数,promise的肯定是异步呀
N
_.map应该就是简单的forEach封装 根据bluebird的文档 Promise.map( Iterable|Promise<Iterable> 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封装的一个工具函数。
M
@noe132 @koroshi 感谢两位回复 我明白了!
参与回复
登录后即可参与回复。登录