Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Can you expain it line by line for me?</p> </blockquote> <p>I'm too lazy, but the nutshell is:</p> <ul> <li>Copy onload to another variable</li> <li>If onload if a function, set it to a new function that runs the passed function then the old function</li> <li>If it isn't, just make the passed function run onload</li> </ul> <blockquote> <p>window.onload = func; //assign 'func' to window.onload event. what does func mean?</p> </blockquote> <p>func is the variable defined as the first argument to the function (function addLoadEvent(func)). Functions are first class objects in JavaScript — you can pass them around, just like any other variable.</p> <blockquote> <p>window.onload is already an event, and why do we use typeof?</p> </blockquote> <p>It isn't an event. It is a property that might be a function or undefined. The event is 'something that happens' which causes that function to be run.</p> <blockquote> <p>function addLoadEvent(func) , window.onload = func, func(). What's the difference among these funcs? </p> </blockquote> <p>The first defines a function named addLoadEvent. The second assigns a function named func to onload. The third calls a function named func.</p> <p>As an aside, don't use this. Use <a href="http://www.quirksmode.org/js/events_advanced.html" rel="nofollow noreferrer">addEventListener/attachEvent</a> or a library that normalises them across browsers such as <a href="http://developer.yahoo.com/yui/event/" rel="nofollow noreferrer">YUI</a> or <a href="http://docs.jquery.com/Events" rel="nofollow noreferrer">jQuery</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload