Bitcoin Forum

Other => Off-topic => Topic started by: payb.tc on November 13, 2011, 09:10:25 AM



Title: jquery document.ready
Post by: payb.tc on November 13, 2011, 09:10:25 AM
if these are 100% equivalent, why on earth would anyone ever use the longer version?

$(document).ready(handler)
$(handler)

i really wonder.



Title: Re: jquery document.ready
Post by: captainteemo on November 15, 2011, 05:02:46 AM
one waits for the page to complete loading, then do actions in the background. if you put this at the top of a page, with a slow thing, it waits for the page to finish
other fires wherever it hits (blocking, non-async) if you put this at the top of a page, it won't finish rendering until it returns


Title: Re: jquery document.ready
Post by: btc_artist on November 15, 2011, 07:24:18 AM
if these are 100% equivalent, why on earth would anyone ever use the longer version?

$(document).ready(handler)
$(handler)

i really wonder.


As far as I know, nobody uses the longer version.  It *is* self-documenting though, which is a plus I guess.


Title: Re: jquery document.ready
Post by: payb.tc on November 15, 2011, 09:46:30 AM
one waits for the page to complete loading, then do actions in the background. if you put this at the top of a page, with a slow thing, it waits for the page to finish
other fires wherever it hits (blocking, non-async) if you put this at the top of a page, it won't finish rendering until it returns

no, they are functionally identical... both only fire when the 'document' is 'ready'... one is just a shorter way of writing it, but i've seen hundreds of examples all over the web that has the longer version in it.


Title: Re: jquery document.ready
Post by: btc_artist on November 15, 2011, 08:27:51 PM
So the answer to your question is probably that people just copy example they see (the long version) and are oblivious to the fact that there's a more concise way to do it.