www.webdeveloper.com
Results 1 to 3 of 3

Thread: calling a function from within another onload function

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    3

    calling a function from within another onload function

    Why will this work:

    window.onload = function () {
    showMeTheDoc('65.xml');
    }

    and this won't ?

    window.onload = showMeTheDoc('65.xml');

    I am inquiring in regards to the principle of calling a function from within another function.
    Why does that work as opposed to calling a function straight away?

    Thanks,
    K.

  2. #2
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    The difference is when the showMeTheDoc function is invoked, and what is assigned to window.onload.

    In your first snippet, you're assigning a reference to a function. When the onload event fires, that function reference is executed, which then executes showMeTheDoc.

    In your second snippet, the showMeTheDoc function is being executed immediately rather than waiting for the onload event, and the return value of that invocation is what is then assigned to window.onload.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

  3. #3
    Join Date
    Jun 2012
    Posts
    3
    hmm... I am still not clear why:

    the first snippet will return a result but the second snippet won't ...
    since they are both running for the first time - right?

    If so then why does something similar - like the below works since it is directly assigned to the onclick event? (just like the window.onload event of my example) ...?

    <a href="#" class="button" onclick="function()"> click me </a>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles