Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Basic questions about $(function() {})

    I'm pretty sure I know the answer to this ...

    If I have
    Code:
    $(function() { stuff1() })
    $(function() { stuff2() })
    will stuff1 run in parallel to stuff2? I think it will ... but I like to make sure.

    Now, I assume that for
    Code:
    $(function() { stuff1(); stuff2() })
    stuff2 will run only after stuff1 runs? Am I correct?
    - - - -

    Is there a document that describes when things run? For instance, do scripts in <head></head> run before scripts in <body></body>?

    I've had a Dickens of a time finding answers to these basic questions. Is there a "basic overview of Javascript multithreading for programmers" somewhere?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Javascript does not support multi-threading. You cannot count on your stuff1 running alongside stuff2 in your first example. Yes, in your second example, the code runs from top to bottom.

    I would suggest if you are worried about multi-threading, you're probably using the wrong language/platform.

  • #3
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I'm not "worried" about multithreading ...
    I simply want to run, say, three animations at the same time.

    Is the way I outlined the way to do it?

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    Quote Originally Posted by Ralph Shnelvar View Post
    I simply want to run, say, three animations at the same time.

    Is the way I outlined the way to do it?
    both approaches you posted should work.
    if in doubt, defer them:
    Code:
    $(function() { setTimeout(stuff1,10);  setTimeout(stuff2,10);  });
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • Users who have thanked rnd me for this post:

    Ralph Shnelvar (04-06-2010)


  •  

    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
    •