Skip to content

Javascript Lazy Function Definition

by Topper on April 29th, 2008

This is an oldy-but-goody.

If you have an expensive function in javascript that will always return the same results… make it do its dirty-work only once:

var foo = function() {
var t = new Date();
foo = function() {
return t;
return foo();