在使用原型时,我需要将所有内容包装在DOM上吗?

时间:2012-10-21 10:56:38

标签: javascript dom prototype

我只是想知道这是否有必要:

;(function ( $, window, document, undefined ) {

    Cluster.prototype.initiate_test_touch_event_support = function(callback) {
        return (Modernizr.touch) ? callback.call(this) : true;
    };

})( jQuery, window, document );

或者我可以使用原型而不将所有东西都包装在DOM上?

1 个答案:

答案 0 :(得分:1)

只要您不试图操纵DOM(访问元素,向元素添加事件等),您就不需要等待文档加载。

这方面的例子是jQuery和prototype.js。两者都允许脚本使用库自己的文档onready / load事件。如果这些库在初始化之前等待文档完成加载,那么这是不可能的。