Calling / Inserting functions before jQuery document.ready

I need to be able to insert or call a function before document.ready () is called in jQuery. I call the document.ready function from another file, which theoretically gives me control over calling document.ready.

Source file (.js):

$(document).ready(function () {
    // some code...
});

Technically, as soon as I call the file with document.ready (), it immediately loads, and I had no chance to find something like the precondition for inserting and calling my function.

Test file (also .js):

// this is a unit testing file, JsTestDriver style
TestFunction.prototype.testFunction = function() {
    // calls my function
    // then calls the document.ready function below
    $.readyList[1]();
}

Since I call the document.ready function from the .js unit test file, the tag

+3
source share
2 answers

Put the code you want to execute before document.ready before document.ready.

+2

ready.

var fn = $.fn;
var realReady = fn.ready;
fn.ready = function ready()
{
    console.log("Before ready.");
    var result = realReady.apply(this, arguments);
    console.log("After ready.");
    return result;
};
0

Source: https://habr.com/ru/post/1727320/


All Articles