25
Aug

JavaScript lazy functions.

I never thought about lazy functions in JavaScript. Apparently, you can implement it this way:

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

I hate JavaScript.

Tags: ,

  • http://www.wonderwhy-er.com wonderwhy-er

    I actually read once that this trick is goodcway to get hidden private varables in JS as they are not scoped to JS global scope and are only seen from inside of such functions.