3 ms·
One-Line Javascript memoization
- 13ren 18y agocute: when the function is run, it calculates the value to be cached, then redefines the function to just return that value. This way, you don't need to check if the value has been calculated yet or not. Yay for self-modifying code.
- gruseom 18y agoMisleading title. It's only one-line if your function has no parameters.