codeing or artist ?
记得大学第一节编程课,教授说,"如果一件事儿有对错,那么是科学。如果有美丑好坏,那么是艺术。" 一个能顺利运行还能让人阅读时体验思维美妙的代码,就是艺术和科学的结合。能运行的程序并不是好程序,能当作文章来读的才是。在我看来代码是一种特殊的文体,程序猿其实会写诗。
var domReady = function( fn ) {

    var isReady = false,

        ready = function(){
            if(!isReady){
                typeof fn === 'function' && fn.call(document);
                isReady = true;
            }
        },

        DOMContentLoaded = function() {
            if ( document.addEventListener ) {
                document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
                ready();
            } else if ( document.readyState === "complete" ) {
                document.detachEvent( "onreadystatechange", DOMContentLoaded );
                ready();
            }
        };
    
    if ( document.readyState === "complete" ) {
        setTimeout( ready, 1 );
    } else if ( document.addEventListener ) {
        document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
        window.addEventListener( "load", ready, false );
    } else {
        document.attachEvent( "onreadystatechange", DOMContentLoaded );
        window.attachEvent( "onload", ready );


        var top = false;

        try {
            top = window.frameElement == null && document.documentElement;
        } catch(e) {}

        if ( top && top.doScroll ) {
            (function doScrollCheck() {
                if ( !isReady ) {
                    try {
                        top.doScroll("left");
                    } catch(e) {
                        return setTimeout( doScrollCheck, 50 );
                    }

                    ready();
                }
            })();
        }
    }
};


//调用
domReady(function(){
    alert(this.getElementById('div1').innerHTML);
});

 

posted on 2016-09-23 23:13  codeing-or-artist-??  阅读(1245)  评论(0编辑  收藏  举报