I'm trying find an explanation to the following question, I looked around and haven't found any awnser so far:  What is the the difference between the Simon Willison's code for the AddLoadEvent function and the load function from jQuery?
Here are the links:
AddLoadEvent code : http://simonwillison.net/2004/May/26/addLoadEvent/
.load function jQuery  see api load from jQuery
function replaceMissingImage(){
    //run code here...
}
$(window).load(function () {
  // run code
  replaceMissingImage();
});
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: Would these two pieces of code do the same thing?
$(window).load(function()) vs AddLoadEvent
Yes, that code does exact the same thing.  jQuery internally uses something very similiar toaddLoadEvent to chain up functions, except it works for all kinds of events for all kinds of elements, not just onload of window.  It is largely based on Dean Edwards' addEvent solution.  I'd recommend viewing the source of jQuery and searching for "edwards" to find this section of code; its flexibility is very impressive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With