daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 16th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Knowing that we have access to whatever
  2. //the user inputs into our function expression, we then write...  
  3. return function(){    
  4.      var key = JSON.stringify(arguments);
  5.      if (cash[key]){
  6.       return cache[key];
  7.      }
  8.    
  9.     else{
  10.       //apply() comes in handy here and will simply
  11.       //return the value of the function it calls
  12.       val = func.apply(this, arguments);
  13.       //then we set the value of the function to the key(argument).
  14.       //The next time the function runs,
  15.       //if the argument is the same, we simply return
  16.       //the value without having to have the function execute.
  17.       cash[key] = val;
  18.       return val;
  19.     }
  20. }
RAW Paste Data
Top