JSPatterns.com » lazy definition

Posts Tagged ‘lazy definition’

Lazy definition function

Tuesday, September 15th, 2009

This has a nice name a lazy function definition. A lazy function is one that pretends to work but it doesn't really.

It does some work initially and then caches the result. Then on consecutive calls it only returns the pre-computed result, it doesnt really do anything.

In order to do so, the function redefines itself with a new implementation, one that simply points to the computed result.

function lazy() {
    var result = 2 + 2;
    lazy = function() {
        return result;
    };
    return lazy();
}
 
lazy(); // 4
lazy(); // 4

hacklink panel bypass shell wso shell evden eve nakliyat hacklink satış hacklink paykasa hacklink hacklink satış hacklink panel hacklink al hacklink satis hacklink hacklink evden eve nakliyat istanbul evden eve nakliyat nakliyat nakliye evden eve nakliyat istanbul evden eve nakliyat nakliyat nakliye depolama Google film izle porno porno izle porno seyret seks hikayeleri Google Evden Eve Nakliyat İstanbul Evden Eve Nakliyat Nakliyat İstanbul Nakliyat istanbul Evden Eve Nakliyat Nakliye Firmaları Şehirler Arası Evden Eve Nakliyat