tadhg.com
tadhg.com
 

Some JavaScript Programming Patterns

15:09 Sun 11 Oct 2009
[, , ]

“JavaScript Programming Patterns”, by Klaus Komenda, is an excellent walkthrough of several JS patterns. If you code JavaScript regularly you probably know at least some of these but will likely still find something useful in it—I particularly like the lazy function definition, a pattern originated by Peter Michaux:

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

Simple, elegant, solves the problem of making sure that the heavy lifting only gets done once.

2 Responses to “Some JavaScript Programming Patterns”

  1. Stephen Casey Says:

    High level, self modifying code? What’s next, goto statements?

  2. Tadhg Says:

    At least one person wants goto functionality in JavaScript

Leave a Reply