Difference between AddLoadEvent and jQuery Download Function

I’m trying to find an explanation on the following question, I looked around and still haven’t found a single teaser: what is the difference between the Simon Willison code for a function AddLoadEventand a function loadfrom jQuery?

Here are the links:

Case No. 1 (jQuery.load function)

function replaceMissingImage(){
    //run code here...
}


$(window).load(function () {
  // run code
  replaceMissingImage();
});

or case number 2 (AddEventLoad - JS)

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function replaceMissingImage(){
    //run code here...
}

addLoadEvent(replaceMissingImage);

Q: Will these two pieces of code do the same?

$(window).load(function()) vs AddLoadEvent

+3
source share
1 answer

, . jQuery - addLoadEvent , , , onload of window. Dean Edwards 'addEvent. jQuery "edwards", ; .

+2

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


All Articles