Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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;
- }
- }
Add Comment
Please, Sign In to add comment