Last active
December 20, 2015 18:14
-
-
Save eternal44/7a42c342abb5209a5ef0 to your computer and use it in GitHub Desktop.
Function decorators
This file contains hidden or 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
_.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