Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
One-Line Javascript memoization (osteele.com)
8 points by soundsop on Sept 6, 2008 | hide | past | favorite | 2 comments


cute: when the function is run, it calculates the value to be cached, then redefines the function to just return that value. This way, you don't need to check if the value has been calculated yet or not.

Yay for self-modifying code.


Misleading title. It's only one-line if your function has no parameters.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: