
本文共 2129 字,大约阅读时间需要 7 分钟。
������������������������������Promise������������������������������������������������������������������������������������
������������
��������������������� fn
������������������Promise���������������500������������������������������������������������������������������ arr1 = [1, 2, 3]
������������ reduce
���������Promise������������������������������������������loop
���������������async
���await
������������������������������������������������������������������������������
������������������ reduce
������������
const fn = function (i) { return new Promise((resolve, reject) => { setTimeout(() => { console.log(i); resolve(); }, 500); });};var arr1 = [1, 2, 3];arr1.reduce((pre, next) => { return pre.then(() => fn(next));}, Promise.resolve());
������������������������������ reduce
������������ then
��������������� next
��������� fn
��������������������������������������������������������������������������������������������� fn
��������������������� then
��������������������������������������� fn
������������������������������������������
������������������ async
��� await
const loop = async function(arr) { for (let i = 0; i < arr.length; i++) { await fn(arr[i]); }};loop(arr1);
������������������������������������ await
������������������������������������������������������ fn
������������������������������������������������������������������������������������������������������������������������������������
������������������
������������������������������������������������������������������������������������������������������������������ reduce
������������������������������������������������������ async/await ���������������������������������������������������
��������������������������������������������������������������������������������������������� reduce
��������������������������� higher-order functions ���������������������������������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
