<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Run Javascript Functions Without using &#8216;domready&#8217; Event</title>
	<atom:link href="http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/</link>
	<description>Sharing what I know and learn about CSS, MooTools, Javascript, PHP and etc.</description>
	<lastBuildDate>Tue, 31 Jan 2012 09:41:19 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Garrick</title>
		<link>http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/comment-page-1/#comment-33</link>
		<dc:creator>Garrick</dc:creator>
		<pubDate>Mon, 24 Nov 2008 08:24:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=125#comment-33</guid>
		<description>@Aaron
Thanks for letting me know more information about the &#039;domready&#039; event. I will keep in mind as I move forward with javascript.</description>
		<content:encoded><![CDATA[<p>@Aaron<br />
Thanks for letting me know more information about the &#8216;domready&#8217; event. I will keep in mind as I move forward with javascript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/comment-page-1/#comment-28</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Tue, 18 Nov 2008 23:56:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.garrickcheung.com/?p=125#comment-28</guid>
		<description>I have a similar pattern that I use (I have an extension for Hash called Hash.run that executes all the methods in a Hash, see: http://www.clientcide.com/docs/Native/Hash.Extras#Hash:run).

But I wanted to point out two things to consider.

First, every time you add a domready event to the window, you&#039;re not adding another event to the window in some way that is an expense. Really you&#039;re doing exactly what you&#039;ve shown above - adding a function to an array of functions that need to be executed when the dom is ready. Calling addEvent on window just pushes the event into an array of methods to call when the event fires. There&#039;s no real expense to adding the event, and there&#039;s no saving of cycles by using your array pattern here.

The second thing to consider is that the domready event keeps track of whether or not the dom has *already* loaded. Meaning that if you add a domready event and domready has already fired, your method will be executed immediately. This is really useful for code that has to occur after domready but you&#039;re not sure when it&#039;s being run (I use this a lot in plugins I release).

I agree that keeping all your &quot;initialize&quot; code in one place is really useful (though it&#039;s not always practical). Using your array method here might feel more tidy than a bunch of domready statements, but it amounts to the same thing - a collection of methods that all run when the document is ready for them.</description>
		<content:encoded><![CDATA[<p>I have a similar pattern that I use (I have an extension for Hash called Hash.run that executes all the methods in a Hash, see: <a href="http://www.clientcide.com/docs/Native/Hash.Extras#Hash:run" rel="nofollow">http://www.clientcide.com/docs/Native/Hash.Extras#Hash:run</a>).</p>
<p>But I wanted to point out two things to consider.</p>
<p>First, every time you add a domready event to the window, you&#8217;re not adding another event to the window in some way that is an expense. Really you&#8217;re doing exactly what you&#8217;ve shown above &#8211; adding a function to an array of functions that need to be executed when the dom is ready. Calling addEvent on window just pushes the event into an array of methods to call when the event fires. There&#8217;s no real expense to adding the event, and there&#8217;s no saving of cycles by using your array pattern here.</p>
<p>The second thing to consider is that the domready event keeps track of whether or not the dom has *already* loaded. Meaning that if you add a domready event and domready has already fired, your method will be executed immediately. This is really useful for code that has to occur after domready but you&#8217;re not sure when it&#8217;s being run (I use this a lot in plugins I release).</p>
<p>I agree that keeping all your &#8220;initialize&#8221; code in one place is really useful (though it&#8217;s not always practical). Using your array method here might feel more tidy than a bunch of domready statements, but it amounts to the same thing &#8211; a collection of methods that all run when the document is ready for them.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

