1const add = () => { 2 const cache = {}; 3 return num => { 4 if (num in cache) { 5 return `From cache! ${cache[num]}`; 6 } else { 7 const result = num + 10; 8 cache[num] = result; 9 return `Calculated! ${result}`; 10 } 11 }; 12}; 13 14const addFunction = add(); 15console.log(addFunction(10)); 16console.log(addFunction(10)); 17console.log(addFunction(5 * 2));
本题为“单选题”