繁体   English   中英

有人可以解释这里发生的步骤流程吗?

[英]Can someone explain the flow of steps that are happening here?

我试图弄清楚每个项目是否在 map 运行时通过 reduce,或者 map 方法是否完全运行,然后在它返回数组后,reduce 方法正在从 Z1D78DC8ED51214E518B5114FEZ2 应用于数组?

 const lineItems = [
{ description: 'Eggs (Dozen)', quantity: 1, price: 3, total: 3 },
{ description: 'Cheese', quantity: 0.5, price: 5, total: 2.5 },
{ description: 'Butter', quantity: 2, price: 6, total: 12 }
];

let store = lineItems.map(item => item.quantity).reduce(sumReducer, 0);

function sumReducer(sum, val) {
  return sum += val;
}

console.log(store);

javascript 中的所有常规 - 非生成器 - 函数都具有运行到完成语义。 这意味着当它们被调用时,执行直到它们返回而不会中断。

在这种情况下, map() function 执行并返回一个数组,然后reduce() function 执行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM