I come across a piece of Javascript code like this one:

 
addDOMLoadEvent = (function() {
    var funcarray = [],
        t, s, n, pushedfunc, o, doc = document,
        w = window,
        r = 'readyState',
        c = 'onreadystatechange',
        x = function() {
            n = 1;
            clearInterval(t);
            while (pushedfunc = funcarray.shift()) pushedfunc();
            if (s) s[c] = ''
        };
    return function(f) {
        if (n) return f();
        if (!funcarray[0]) {
            doc.addEventListener && doc.addEventListener("DOMContentLoaded", x, false); /*@cc_on@*/
            /*@if(@_win32)d.write("<script id=__ie_onload defer src=//0><\/scr"+"ipt>");s=d.getElementById("__ie_onload");s[c]=function(){s[r]=="complete"&&x()};/*@end@*/
            if (/WebKit/i.test(navigator.userAgent)) t = setInterval(function() {
                /loaded|complete/.test(doc[r]) && x()
            }, 10);
            o = w.onload;
            w.onload = function() {
                x();
                o && o()
            }
        }
        funcarray.push(f)
    }
})();
 

Its packed, but then I found the unpacked and improved version:

 
addDOMLoadEvent = (function(){
    // create event function stack
    var load_events = [],safari_timer,done,exec,script;
 
    var init = function () {
            done = true;
 
            // kill the timer
            clearInterval(safari_timer);
 
            // execute each function in the stack in the order they were added
            while (exec = load_events.shift())
                exec();
 
            if (script) script.onreadystatechange = '';
        }
 
    return function (func) {
        // if the init function was already ran, just run this function now and stop
        if (done) return func();
 
        if (!load_events[0]) {
            // for Mozilla/Opera9
            if (document.addEventListener)
                document.addEventListener("DOMContentLoaded", init, false);
 
   /*@cc_on @*/
   /*@if (@_win32)
   var proto = "src='javascript:void(0)'";
   if (location.protocol == "https:") proto = "src=//0";
   document.write("<scr"+"ipt id=__ie_onload defer " + proto + ">< \/scr"+"ipt>");
   var script = document.getElementById("__ie_onload");
   script.onreadystatechange = function() {
    if (this.readyState == "complete") {
     init()
    }
   };
   /*@end @*/
 
            if (/WebKit/i.test(navigator.userAgent)) { // sniff
                safari_timer = setInterval(function() {
                    if (/loaded|complete/.test(document.readyState))
                        init(); // call the onload handler
                }, 10);
            }
 
            old_onload = window.onload;
            window.onload = function() {
                init();
                if (old_onload) old_onload();
            };
        }
 
        load_events.push(func);
    }
})();
 

Its just the same as jQuery.ready function . All the function add to load_events will wait until the DOM was loaded, but don't have to wait for all images and text loaded.

Find more here http://www.thefutureoftheweb.com/blog/adddomloadevent