memoize
Returns the memoized (cached) function.
- Create an empty cache by instantiating a new
Mapobject. - Return a function which takes a single argument to be supplied to the memoized function by first checking if the function's output for that specific input value is already cached, or store and return it if not.
- The
functionkeyword must be used in order to allow the memoized function to have itsthiscontext changed if necessary. - Allow access to the
cacheby setting it as a property on the returned function.