完全没写出来,惨~
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>纯函数默写第二遍</title> </head> <body> <script> function getArea(r) { return Math.PI * r * r; } // 纯函数:相同的输入会有相同的输出 function memorize(func) { let obj = {}; return function () { let key = JSON.stringify([...arguments]); if (!obj[key]) { console.log(123); obj[key] = func(...arguments); } return obj[key]; }; } </script> </body> </html>