我想知道如何使用 javascript 在 forEach() 中进行函数调用。
下面的函数工作正常,但由于 indoTransCalc和doFundCalc,计算是相似的,有没有其他方法可以做到这一点。
var objFund = [{
"sucess": "true",
"id": "fund",
"options": "others",
"fee": 3,
"tax": 0.3,
"amount": 2000
}]
var objTrans = [{
"sucess": "true",
"id": "trans",
"options": "service",
"fee": 2,
"tax": 0.4,
"amount": 1000
}]
function doTransCalc(trans) {
trans.forEach(e => {
if (e.success) {
e.rate = 2.0,
e.netFee = e.fee + e.tax,
e.amountwithfee = e.amount + e.netfee,
e.total = e.amountwithfee * e.rate;
}
})
}
function doFundCalc(fund) {
fund.forEach(e => {
if (e.success) {
e.rate = 4.0,
e.addfee = 10,
e.netFee = e.fee + e.tax,
e.amountwithfee = e.amount + e.netfee,
e.total = e.amountwithfee * e.rate;
}
})
}
doTransCalc(objTrans);
doFundCalc(objFund);
console.log(objTrans);
console.log(objFund);
斯蒂芬大帝
相关分类