Created
July 17, 2015 20:32
-
-
Save kylebakerio/0cbcc4058b1906a1780c 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
var memoize3 = function(func) { | |
var memoized = function(key) { | |
if (!memoized.cache.hasOwnProperty(key)) memoized.cache[key] = func.apply(this, arguments); | |
return memoized.cache[key] | |
} | |
memoized.cache = {}; | |
return memoized; | |
} | |
//this works. But, I feel disingenuous using ".apply", because I don't fully understand it yet. | |
//vs, what I was trying to do: | |
var memoize3 = function(func) { | |
var memoized = function(key) { | |
var funcStore = func; | |
if (!memoized.cache.hasOwnProperty(key)) memoized.cache[key] = funcStore(key); | |
return memoized.cache[key] | |
} | |
memoized.cache = {}; | |
return memoized; | |
} | |
/*------*/ | |
Is there some rule against defining a function inside a function, and then running it inside of that function as a subroutine when called? Some syntax error I'm making? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment