直接上代码,如下所示 let a = {}; function f(n){ if(a.hasOwnProperty(n)){ return a[n]; } let b = n == 0 || n == 1 ? 1 : f(n - 1) + f(n - 2); a[n] = b; return b } console.log(f(6));