Call order of jQuery ready callback

☆樱花仙子☆ 提交于 2019-12-01 22:10:21

jQuery ready uses the Deferred object system :

ready: function( fn ) {
    // Add the callback
    jQuery.ready.promise().done( fn );

    return this;
},

(from the source code)

And the documentation states that

Callbacks are executed in the order they were added

So yes, your callbacks will be executed in order of addition.

If you want these functions to be executed in order, why don't you just write:

$(document).ready(function(){ 
    function1();
    function2();
});

Better make use of callback function to be sure about the execution order of the functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!