Skip to content

Instantly share code, notes, and snippets.

@eternal44
Last active December 20, 2015 18:14
Show Gist options
  • Save eternal44/7a42c342abb5209a5ef0 to your computer and use it in GitHub Desktop.
Save eternal44/7a42c342abb5209a5ef0 to your computer and use it in GitHub Desktop.
Function decorators
_.memoize = function(func) {
var history = {};
/* PSEUDO CODE
check if func & arguments in history
if they are: look up the stored return value
if not: run it with 'once' and store it in 'history' as an object with 3 properties:
history = {
{
function: ____,
arguments: _____,
returnedValue: _____
}
}
*/
// failing function - attempting to access arguments in this closure
return _.once(function(){
return func.call(null, arguments);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment