As @Bergi and @BenjaminGruenbaum pointed out, yes, the memories are wonderful, but it should be noted that your foo function does nothing useful and actually introduces errors (see deferred antipattern).
If all you want is to memoize the result of doSomethingAsync , you can cut out the average person:
var fooMemoized = memoize(doSomethingAsync);
Or, if you really simplify, and foo() passes arguments to doSomethingAsync , you can reduce it to one line:
function foo() { return doSomethingAsync(argument1, argument2, etc.); } var fooMemoized = memoize(foo);
Or, if you are not really planning on using foo() , you can do:
var fooMemoized = memoize(function () { return doSomethingAsync(argument1, argument2, etc.); });
source share