1、通过使用invoice.performances.map返回一个新的拷贝对象
function createStatementData(invoice,plays){
const result={};
result.performances=invoice.performances.map(enrichPerformance);
}
2、enrichPerformance为回调函数,通过Object.assign拷贝新的对象
function enrichPerformance(aPerformance){
const calculator =createPerformanceCalculator(aPerformance,playFor(aPerformance));
const result = Object.assign({},aPerformance);
result.play=calculator.play;
result.amount = calculator.amount;
result.volumeCredits=calculator.volumeCredits;
return result;
}
function createPerformanceCalculator(aPerformance,aPlay){
switch(aPlay.type)
{
case "tragedy": return new TragedyCalculator(aPerformance,aPlay);