Wednesday, August 15, 2007

Definitions for the Lazy

This is bloody interesting (via Ajaxian). It involves creating functions at call time, where some expensive initial operation us computed and placed in a new function, which is then used to replace the original one.

For example,

function MyObject() {
this.someFunction = function(x) {
var a = someComplexCalculation();
this.someFunction = function(y) {
return a + y;
};
return this.someFunction(x);
}
}


Pretty sweet.