Last active
October 2, 2021 21:18
-
-
Save rayinla/2a2460b807a095b124aaca7646ead065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Knowing that we have access to whatever | |
//the user inputs into our function expression, we then write... | |
return function(){ | |
var key = JSON.stringify(arguments); | |
if (cash[key]){ | |
return cache[key]; | |
} | |
else{ | |
//apply() comes in handy here and will simply | |
//return the value of the function it calls | |
val = func.apply(this, arguments); | |
//then we set the value of the function to the key(argument). | |
//The next time the function runs, | |
//if the argument is the same, we simply return | |
//the value without having to have the function execute. | |
cash[key] = val; | |
return val; | |
} | |
} | |
@rayinla There is typo in above gist
if (cash[key]){} should be
if (cache[key]){}
similarly in else condition. See cash[key] = val;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/rayinla/2a2460b807a095b124aaca7646ead065#file-memo-strip2-js-L5 $$$