相关疑难解决方法(0)

什么是参考透明度?

参考透明度这个术语是什么意思?我听说它被描述为"它意味着你可以用平等替换等于",但这似乎是一个不充分的解释.

theory computer-science functional-programming referential-transparency

267
推荐指数
10
解决办法
5万
查看次数

How to implement memoization with "pure" Functional Programming in JavaScript

In all the examples I can find on memoization / internal function cache in Functional Programming in JavaScript, the examples are either mutating or reassigning the cache.

Here's an example taken from https://scotch.io/tutorials/understanding-memoization-in-javascript#toc-a-functional-approach

function memoizer(fun){
    let cache = {}
    return function (n){
        if (cache[n] != undefined ) {
          return cache[n]
        } else {
          let result = fun(n)
          cache[n] = result
          return result
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

The only tiny improvement I can come up with is to use reassigning instead of …

javascript functional-programming

5
推荐指数
2
解决办法
1793
查看次数