<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" 
	xmlns:dc="http://purl.org/dc/elements/1.1/" 
	xmlns:rcb="http://www.brothercake.com/ns/rcb/">
	<channel>
		<title>Discuss: domFunction</title>
		<link>http://www.brothercake.com/discuss/resources/scripts/domready/</link>
		<description>Allows DOM scripting to run before window.onload</description>
		<language>en</language>

		<item rcb:parse="yes">
			<title>RE: domFunction: error handling</title>
			<link>http://www.brothercake.com/discuss/resources/scripts/domready/#comment1</link>
			<dc:creator>Morgan Knicely</dc:creator>
			<dc:date>2006-02-21T01:24:03+00:00</dc:date>
			<description><![CDATA[ <p>I&#039;ve noticed that if I use domFunction to call a function that has bugs, the script will loop endlessly inserting error messages in the console as it goes.  Eeek!  Example:</p><p>function snafu() {
<br />&nbsp;&nbsp;&nbsp;&nbsp;blah;
<br />}
<br />var foobar = new domFunction(function() {
<br />&nbsp;&nbsp;&nbsp;&nbsp;snafu();
<br />});</p><p>So I added a try...catch statement to the portion of domFunction that executes the desired code.  Change lines 57-58 of the original script:</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//we can call the argument function and clear the timer
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!c) { f(); clearInterval(t); }</p><p>To:
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//we can call the argument function and clear the timer
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(!c) {
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f();
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch(err) {
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(&#039;Error: &#039; + err.description);
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clearInterval(t);
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p><p>What do you think of the change?  I&#039;m looking into making the alert message more informative, and possibly routing it to the Firefox console when available.</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title>RE: domFunction</title>
			<link></link>
			<dc:creator>brothercake</dc:creator>
			<dc:date>2006-02-22T08:10:28+00:00</dc:date>
			<description><![CDATA[ <p><q>What do you think of the change? I&#039;m looking into making the alert message more informative, and possibly routing it to the Firefox console when available.</q></p><p>I like it :^) I&#039;ve noticed the same problem, and it can be rather insane, as it loops through the timeout throwing the same error into the console over and over again! </p><p>But I hadn&#039;t thought of using a <code>try{} catch{}</code> construct .. that&#039;s probably the way to go, yeah :)</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title>RE: domFunction</title>
			<link></link>
			<dc:creator>johan duflost</dc:creator>
			<dc:date>2006-08-03T06:01:40+00:00</dc:date>
			<description><![CDATA[ <p>
<br />Hello,</p><p>I get this error message in firefox in the demo page:</p><p>Error: uncaught exception: [Exception... &quot;Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindowInternal.focus]&quot;  nsresult: &quot;0x80004005 (NS_ERROR_FAILURE)&quot;  location: &quot;JS frame :: chrome://global/content/bindings/tabbrowser.xml :: setFocus :: line 753&quot;  data: no]</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[RE: domFunction]]></title>
			<link>http://www.brothercake.com/discuss/resources/scripts/domready/#comment1</link>
			<dc:creator><![CDATA[brothercake]]></dc:creator>
			<dc:date>2006-09-05T01:17:53+00:00</dc:date>
			<description><![CDATA[ <p>That error is coming from the Firefox chrome itself; do you have an extensions installed? It&#039;s most likely coming from one of them.</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[RE: domFunction]]></title>
			<link></link>
			<dc:creator><![CDATA[Jerome]]></dc:creator>
			<dc:date>2006-09-09T17:21:36+00:00</dc:date>
			<description><![CDATA[ <p>Just a small suggestion for domFunction... as .js files are loaded asynchronously it would be possible to attempt to call a function, somewhere down the callstack from domFunction, that doesn&#039;t actually exist yet. How about expanding the existence checking code to include functions?</p><p>//if its value is &quot;id&quot; and the element with the given ID doesn&#039;t exist 
<br />//or its value is &quot;tag&quot; and the specified collection has no members
<br />if
<br />(
<br />&nbsp;&nbsp;&nbsp;&nbsp;(a[i] == &#039;id&#039; &amp;&amp; document.getElementById(i) == null)
<br />&nbsp;&nbsp;&nbsp;&nbsp;||
<br />&nbsp;&nbsp;&nbsp;&nbsp;(a[i] == &#039;tag&#039; &amp;&amp; document.getElementsByTagName(i).length &lt; 1)
<br />&nbsp;&nbsp;&nbsp;&nbsp;||
<br />&nbsp;&nbsp;&nbsp;&nbsp;(a[i] == &#039;function&#039; &amp;&amp; window[i])
<br />) </p><p>No need to check for all the functions you want to use, of course - just one from any .js file you rely on.</p><p>Anyway, just a thought (haven&#039;t actually tried it yet!). Thanks for the really useful bit of code :)</p><p>P.S. Looking at the error trapping mod above, it might be slightly better to re-throw like this:</p><p>//we can call the argument function and clear the timer
<br />if(!c) {
<br />&nbsp;&nbsp;&nbsp;&nbsp;try {
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f();
<br />&nbsp;&nbsp;&nbsp;&nbsp;} catch(err) {
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throw err;
<br />&nbsp;&nbsp;&nbsp;&nbsp;} finally {
<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clearInterval(t);
<br />&nbsp;&nbsp;&nbsp;&nbsp;}
<br />}</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[RE: domFunction]]></title>
			<link>http://www.brothercake.com/discuss/resources/scripts/domready/#comment1</link>
			<dc:creator><![CDATA[Jerome]]></dc:creator>
			<dc:date>2006-09-09T17:24:52+00:00</dc:date>
			<description><![CDATA[ <p>Oops, sorry - that should have been:</p><p>//if its value is &quot;id&quot; and the element with the given ID doesn&#039;t exist 
<br />//or its value is &quot;tag&quot; and the specified collection has no members
<br />//or its value is &quot;function&quot; and the specified function doesn&#039;t exist
<br />if
<br />(
<br />    (a[i] == &#039;id&#039; &amp;&amp; document.getElementById(i) == null)
<br />    ||
<br />    (a[i] == &#039;tag&#039; &amp;&amp; document.getElementsByTagName(i).length &lt; 1)
<br />    ||
<br />    (a[i] == &#039;function&#039; &amp;&amp; !window[i])
<br />)</p><p>Note the ! before window[i]</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[RE: domFunction]]></title>
			<link>http://www.brothercake.com/discuss/resources/scripts/domready/#comment2</link>
			<dc:creator><![CDATA[brothercake]]></dc:creator>
			<dc:date>2006-09-12T01:45:35+00:00</dc:date>
			<description><![CDATA[ <p><q>as .js files are loaded asynchronously it would be possible to attempt to call a function, somewhere down the callstack from domFunction, that doesn&#039;t actually exist yet</q></p><p>That&#039;s not true - JS files are loaded synchronously unless you use the [unreliable] &quot;defer&quot; attribute.</p><p>The problem here is the structure of your codebase; you&#039;re relying on dependencies that don&#039;t exist when you need them, and that&#039;s an architecture issue - something you can resolve manually by attention to dependency structures. </p><p>I&#039;m guessing here that you&#039;re using a generalised framework like prototype? If so, that certainly won&#039;t make your job easier, because following dependency chains in external frameworks can be notoriously difficult (and is, in my view, a reason for not using them; but that&#039;s another argument for another time!)</p><p>I do appreciate however that a timed solution would fix this potential issue more swiftly in specific cases, but it&#039;s really a case of patchwork, of providing a temporary solution to a problem that you&#039;d be much better advised to address at its root.</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[RE: domFunction]]></title>
			<link>http://www.brothercake.com/discuss/resources/scripts/domready/#comment3</link>
			<dc:creator><![CDATA[brothercake]]></dc:creator>
			<dc:date>2006-09-12T01:47:45+00:00</dc:date>
			<description><![CDATA[ <p>btw, this example:</p><p><code>(a[i] == &#039;function&#039; &amp;&amp; !window[i])</code></p><p>should be like this:</p><p><code>(a[i] == &#039;function&#039; &amp;&amp; typeof window[i] == &#039;undefined&#039;)</code></p><p>But even then, it would of course only work for functions in the window scope.</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[RE: domFunction]]></title>
			<link>http://www.brothercake.com/discuss/resources/scripts/domready/#comment4</link>
			<dc:creator><![CDATA[brothercake]]></dc:creator>
			<dc:date>2006-09-12T18:46:29+00:00</dc:date>
			<description><![CDATA[ <p>Re: PS - thanks for the <code>throw</code> code - that&#039;s much better :)</p> ]]></description>
		</item>

		<item rcb:parse="yes">
			<title><![CDATA[Alex]]></title>
			<link></link>
			<dc:creator><![CDATA[http://www.google.com]]></dc:creator>
			<dc:date>2007-04-23T00:18:46+00:00</dc:date>
			<description><![CDATA[ <p>Thank You</p> ]]></description>
		</item>

		

		
		
	</channel>

</rss>