It's not multithreading. Rather, it's very similar to the event model in node. When div1 animates a little (say, a pixel), it registers an event to be fired in the next split second; when that event fires, it animates a little more, and registers yet another event. For div2 it is the same, meaning that the events for div2 will likely be fired in that split second where div1 is idle and waiting for its next event. There are almost always two callbacks waiting in line, and each callback only does a very subtle animation, so it looks like they are animated in concert as with two threads. Actually it's still just one thread. ======================= 杨旭东 YANG Xudong "Wyverald" Twitter <http://twitter.com/Wyverald> - Tumblr <http://wyverald.tumblr.com/>- GitHub <https://github.com/Wyverald> - Douban<http://www.douban.com/people/45985185/> Juntos, unidos, triunfará nuestro deseo de ser el mejor alias please=sudo please rm -rf /
On Fri, Dec 17, 2010 at 11:51, Yu-Hsuan Lai <[email protected]> wrote: > Uh... I guessed it use setTimeout, but I read this: > http://ejohn.org/blog/how-javascript-timers-work/ > <http://ejohn.org/blog/how-javascript-timers-work/>SetTimeout seems can't > emulate threads, it really confuse me. > > > On Fri, Dec 17, 2010 at 11:41 AM, Anton Yacenko > <[email protected]>wrote: > >> It's implemented with setTimeout. >> setTimeout is not a part of ECMA specification. >> It's basically a trick, that implemented in browsers, so it's our >> "threads" emulation :) >> >> Anton. >> >> On Dec 17, 2010, at 5:33 AM, Yu-Hsuan Lai wrote: >> >> Thanks for the resources.( though my listening skill is not enough to >> understand the speech...) >> >> Another question: >> If I have two jquery.animation like below: >> $(".div1").animate({width:10},"slow"); >> $(".div2").animate({width:1000},"slow"); >> div1 and div2 will change their width "synchronously", but doesn't >> javascript have only one thread? >> How do jquery implement it? >> >> On Fri, Dec 17, 2010 at 10:32 AM, Chris Williams <[email protected]> wrote: >> >>> >>> There are various advantages (simplicity, comprehensibility, flexibility) >>> that single threaded, evented models have over multi-threaded paradigm. The >>> biggest argument is that threading is hard and not many people actually know >>> how to do it properly. >>> >>> >>> Brendan Eich (creator of JS) spoken on this in November, give it a >>> listen: http://www.aminutewithbrendan.com/pages/20101108 >>> >>> -- >>> Chris Williams >>> >>> Twitter: http://twitter.com/voodootikigod >>> OurParents: http://ourparents.com >>> JSConf US: http://jsconf.us >>> Minute With: http://minutewith.com >>> >>> On Thursday, December 16, 2010 at 9:31 PM, Chris Williams wrote: >>> >>> >>> There are various advantages (simplicity, comprehensibility, flexibility) >>> that single threaded, evented models have over multi-threaded paradigm. The >>> biggest argument is that threading is hard and not many people actually know >>> how to do it properly. >>> >>> Brendan Eich (creator of JS) spoken on this in November, give it a >>> listen: http://www.aminutewithbrendan.com/pages/20101108 >>> >>> -- >>> Chris Williams >>> >>> Twitter: http://twitter.com/voodootikigod >>> OurParents: http://ourparents.com >>> JSConf US: http://jsconf.us >>> Minute With: http://minutewith.com >>> >>> On Thursday, December 16, 2010 at 9:25 PM, Yu-Hsuan Lai wrote: >>> >>> Javascript is a functional language, it's proper to design thread-safe >>> program. >>> And most modern language can support multi-threading programming. >>> It's just a legacy? Or single thread has some advantages for javascript? >>> >>> -- >>> Lai, Yu-Hsuan >>> >>> -- >>> To view archived discussions from the original JSMentors Mailman list: >>> http://www.mail-archive.com/[email protected]/ >>> >>> To search via a non-Google archive, visit here: >>> http://www.mail-archive.com/[email protected]/ >>> >>> To unsubscribe from this group, send email to >>> [email protected] >>> >>> >>> >>> >>> -- >>> To view archived discussions from the original JSMentors Mailman list: >>> http://www.mail-archive.com/[email protected]/ >>> >>> To search via a non-Google archive, visit here: >>> http://www.mail-archive.com/[email protected]/ >>> >>> To unsubscribe from this group, send email to >>> [email protected]<jsmentors%[email protected]> >>> >> >> >> >> -- >> Lai, Yu-Hsuan >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/[email protected]/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/[email protected]/ >> >> To unsubscribe from this group, send email to >> [email protected] >> >> >> -- >> To view archived discussions from the original JSMentors Mailman list: >> http://www.mail-archive.com/[email protected]/ >> >> To search via a non-Google archive, visit here: >> http://www.mail-archive.com/[email protected]/ >> >> To unsubscribe from this group, send email to >> [email protected]<jsmentors%[email protected]> >> > > > > -- > Lai, Yu-Hsuan > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected]<jsmentors%[email protected]> > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
