Javascript Lazy Function Definition
04.29.08 - 04:35pm
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:
JavaScript:
var foo = function() {
var t = new Date();
foo = function() {
return t;
};
return foo();
};
var t = new Date();
foo = function() {
return t;
};
return foo();
};
Speak Your Peace