Simple memoization in js