As @Bergi, and @BenjaminGruenbaum have pointed out, yes memoization is fine here, but it should be pointed out that your foo
function is doing nothing useful and is actually introducing bugs (see: deferred antipattern).
If all you want is to memoize the result of doSomethingAsync
, then you can cut out the middle-man:
var fooMemoized = memoize(doSomethingAsync);
Or if you were actually oversimplifying and foo()
is passing arguments to doSomethingAsync
, then you can still reduce it to one line:
function foo() {
return doSomethingAsync(argument1, argument2, etc.);
}
var fooMemoized = memoize(foo);
Or if you don't actually plan to use foo()
, you can do:
var fooMemoized = memoize(function () {
return doSomethingAsync(argument1, argument2, etc.);
});