将地图功能导出到其他文件

Exporting map function into other file

是否可以导出orders.map里面的函数,也就是'order',然后导入到另一个里面有函数的JS文件中?我收到错误订单未定义。谢谢

main.js

     const getReport = async function() {
      const jsonlUrl = 'https://next.json-generator.com/api/json/get/xxxxx'
      const res = await fetch(jsonlUrl);
      const orders = await res.json();

      const orderlines = orders.map(order => ({

       order_id: order.order_id,

      customer_name: getName()

      }));

---

function.js

const getName = function() {
const customerName = order.customer_name
 return customerName
}

已解决: 将参数传递给函数调用

main.js
     const getReport = async function() {
      const jsonlUrl = 'https://next.json-generator.com/api/json/get/xxxxx'
      const res = await fetch(jsonlUrl);
      const orders = await res.json();

      const orderlines = orders.map(order => ({

       order_id: order.order_id,

      customer_name: getName(order)

      }));

我在函数 getName 上添加了参数

function.js
const getName = function(order) { 
const customerName = order.customer_name 
return customerName 
}