<?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: A safety fence for your property lookups</title>
	<atom:link href="http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:55:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
	<item>
		<title>By: matanlurey</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265834</link>
		<dc:creator>matanlurey</dc:creator>
		<pubDate>Mon, 14 Jul 2008 22:51:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265834</guid>
		<description>@RichB
(object&#124;&#124;{}).property is less efficient due to the fact than an anonymous object needs to be created - in a tight loop of hundreds of iterations it will be noticeable.</description>
		<content:encoded><![CDATA[<p>@RichB<br />
(object||{}).property is less efficient due to the fact than an anonymous object needs to be created &#8211; in a tight loop of hundreds of iterations it will be noticeable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: LeoHorie</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265830</link>
		<dc:creator>LeoHorie</dc:creator>
		<pubDate>Mon, 14 Jul 2008 18:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265830</guid>
		<description>heh, so many different ways of accomplishing the same thing :)

@linb: I like your function. One could use a variadic function instead of passing a second parameter as an array for the extra sugar punch (i.e. so the function call looks like get(node, &quot;nextSibling&quot;, &quot;className&quot;) ), though I suspect some people might object with hypothetical performance issues with the body of the function itself.</description>
		<content:encoded><![CDATA[<p>heh, so many different ways of accomplishing the same thing :)</p>
<p>@linb: I like your function. One could use a variadic function instead of passing a second parameter as an array for the extra sugar punch (i.e. so the function call looks like get(node, &#8220;nextSibling&#8221;, &#8220;className&#8221;) ), though I suspect some people might object with hypothetical performance issues with the body of the function itself.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MauriceSchoenmakers</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265824</link>
		<dc:creator>MauriceSchoenmakers</dc:creator>
		<pubDate>Sun, 13 Jul 2008 18:57:22 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265824</guid>
		<description>compare :
&lt;code&gt;
       var r; if(node&amp;&amp;node.nextSibling&amp;&amp;(r=node.nextSibling.className)==&#039;x&#039;) return r;
        var r; if((r=((node&#124;&#124;0).nextSibling&#124;&#124;0).className)==&#039;x&#039;) return r;
        
        var r; if(r=node)if(r=r.nextSibling)if((r=r.className)==&#039;x&#039;) return r;
&lt;/code&gt;
Using a simple if is maybe a bit longer but faster :-)</description>
		<content:encoded><![CDATA[<p>compare :<br />
<code><br />
       var r; if(node&amp;&amp;node.nextSibling&amp;&amp;(r=node.nextSibling.className)=='x') return r;<br />
        var r; if((r=((node||0).nextSibling||0).className)=='x') return r;</p>
<p>        var r; if(r=node)if(r=r.nextSibling)if((r=r.className)=='x') return r;<br />
</code><br />
Using a simple if is maybe a bit longer but faster :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KKFC</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265817</link>
		<dc:creator>KKFC</dc:creator>
		<pubDate>Sat, 12 Jul 2008 11:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265817</guid>
		<description>Thanks your fenceï¼</description>
		<content:encoded><![CDATA[<p>Thanks your fenceï¼</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RichB</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265816</link>
		<dc:creator>RichB</dc:creator>
		<pubDate>Sat, 12 Jul 2008 09:58:46 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265816</guid>
		<description>This has been mentioned before with Oliver Steele&#039;s Maybe Monads on the cheap where he recommends the following maybe monad null propagation behaviour:

(object&#124;&#124;{}).property

http://osteele.com/archives/2007/12/cheap-monads</description>
		<content:encoded><![CDATA[<p>This has been mentioned before with Oliver Steele&#8217;s Maybe Monads on the cheap where he recommends the following maybe monad null propagation behaviour:</p>
<p>(object||{}).property</p>
<p><a href="http://osteele.com/archives/2007/12/cheap-monads" rel="nofollow">http://osteele.com/archives/2007/12/cheap-monads</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: linb</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265815</link>
		<dc:creator>linb</dc:creator>
		<pubDate>Sat, 12 Jul 2008 09:25:16 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265815</guid>
		<description>I use &lt;a href=&quot;http://code.google.com/p/linb/source/browse/trunk/VisualJS1.2/jsLinb/js/linb.js#60&quot; title=&quot;jsLinb&quot; rel=&quot;nofollow&quot;&gt;This get function&lt;/a&gt;:
&lt;code&gt;
get=function(hash,arr){
    for(var i=0,l=arr.length;i&lt;l;)
        if(!hash &#124;&#124; (hash=hash[arr[i++]])===undefined )return;
    return hash;
}
//And
if(get(node,[&#039;nextSiÂ­bling&#039;, &#039;clasÂ­sName&#039;])){
    ...
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>I use <a href="http://code.google.com/p/linb/source/browse/trunk/VisualJS1.2/jsLinb/js/linb.js#60" title="jsLinb" rel="nofollow">This get function</a>:<br />
<code><br />
get=function(hash,arr){<br />
    for(var i=0,l=arr.length;i&lt;l;)<br />
        if(!hash || (hash=hash[arr[i++]])===undefined )return;<br />
    return hash;<br />
}<br />
//And<br />
if(get(node,['nextSiÂ­bling', 'clasÂ­sName'])){<br />
    ...<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eyelidlessness</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265813</link>
		<dc:creator>eyelidlessness</dc:creator>
		<pubDate>Sat, 12 Jul 2008 03:31:37 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265813</guid>
		<description>@bosmeeuw, philm:
I think if, upon reading an explanation of what it does, you still find it unreadable, you&#039;re probably doing something wrong.
.
@Nosredna:
I am on the fence; I think the &quot;syntactic sugar&quot; might eventually prove beneficial enough that the parens could become reflex.
.
As for &#124;&#124; vs &amp;&amp;, first of all, if that&#039;s your bottleneck, you need to rethink your approach. Second of all, just make sure you use the optimal condition order for your use case.</description>
		<content:encoded><![CDATA[<p>@bosmeeuw, philm:<br />
I think if, upon reading an explanation of what it does, you still find it unreadable, you&#8217;re probably doing something wrong.<br />
.<br />
@Nosredna:<br />
I am on the fence; I think the &#8220;syntactic sugar&#8221; might eventually prove beneficial enough that the parens could become reflex.<br />
.<br />
As for || vs &amp;&amp;, first of all, if that&#8217;s your bottleneck, you need to rethink your approach. Second of all, just make sure you use the optimal condition order for your use case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jguide</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265808</link>
		<dc:creator>jguide</dc:creator>
		<pubDate>Fri, 11 Jul 2008 19:33:59 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265808</guid>
		<description>Well, unless speed was of the utmost importance, as in a game, wouldn&#039;t this simply be a case where a try/catch block would be much clearer:

&lt;code&gt;
try{
     if (node.nextSibling.className == &quot;something&quot;)
     // do something
}
catch(e) {
     // catch error
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Well, unless speed was of the utmost importance, as in a game, wouldn&#8217;t this simply be a case where a try/catch block would be much clearer:</p>
<p><code><br />
try{<br />
     if (node.nextSibling.className == "something")<br />
     // do something<br />
}<br />
catch(e) {<br />
     // catch error<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nosredna</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265806</link>
		<dc:creator>Nosredna</dc:creator>
		<pubDate>Fri, 11 Jul 2008 19:17:24 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265806</guid>
		<description>Also, sometimes these tricks are useful for people writing compilers that target JS as an assembly language. Shorter is usually better in those cases. You might generate the more typical code for debugging and the tighter code for production.
.
Another problem, though, is that the &amp;&amp; will shortcut out, so it&#039;s probably faster than the &#124;&#124; solution.</description>
		<content:encoded><![CDATA[<p>Also, sometimes these tricks are useful for people writing compilers that target JS as an assembly language. Shorter is usually better in those cases. You might generate the more typical code for debugging and the tighter code for production.<br />
.<br />
Another problem, though, is that the &amp;&amp; will shortcut out, so it&#8217;s probably faster than the || solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nosredna</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265805</link>
		<dc:creator>Nosredna</dc:creator>
		<pubDate>Fri, 11 Jul 2008 19:14:14 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265805</guid>
		<description>It is shorter, and I don&#039;t find it unreadable at all. I know right away when I see it that the programmer is trying to guard against a missing attribute.
.
But I don&#039;t think I&#039;d do it (for me, the less parens the better).
.
I do like to see these things, though. Good for the brain.</description>
		<content:encoded><![CDATA[<p>It is shorter, and I don&#8217;t find it unreadable at all. I know right away when I see it that the programmer is trying to guard against a missing attribute.<br />
.<br />
But I don&#8217;t think I&#8217;d do it (for me, the less parens the better).<br />
.<br />
I do like to see these things, though. Good for the brain.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: philm</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265800</link>
		<dc:creator>philm</dc:creator>
		<pubDate>Fri, 11 Jul 2008 14:13:23 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265800</guid>
		<description>&lt;code&gt;if (((node &#124;&#124; 0).nextSibling &#124;&#124; 0).className == &#039;hello&#039;) &lt;/code&gt;

&lt;code&gt;if (node &amp;&amp; node.nextSibling &amp;&amp; node.nextSibling.className == &#039;hello&#039;) &lt;/code&gt;

The &#039;neat trick&#039; isn&#039;t that much shorter and a lot less readable! Must agree with bosmeeuw</description>
		<content:encoded><![CDATA[<p><code>if (((node || 0).nextSibling || 0).className == 'hello') </code></p>
<p><code>if (node &amp;&amp; node.nextSibling &amp;&amp; node.nextSibling.className == 'hello') </code></p>
<p>The &#8216;neat trick&#8217; isn&#8217;t that much shorter and a lot less readable! Must agree with bosmeeuw</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bosmeeuw</title>
		<link>http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups/comment-page-1#comment-265799</link>
		<dc:creator>bosmeeuw</dc:creator>
		<pubDate>Fri, 11 Jul 2008 13:38:31 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/archives/a-safety-fence-for-your-property-lookups#comment-265799</guid>
		<description>Nice, this turns the if clause which clearly expresses that the developer expects node or node.nextSibling to possibly be null into an clever/unreadable hack! If only more people properly abused language constructs this way..</description>
		<content:encoded><![CDATA[<p>Nice, this turns the if clause which clearly expresses that the developer expects node or node.nextSibling to possibly be null into an clever/unreadable hack! If only more people properly abused language constructs this way..</p>
]]></content:encoded>
	</item>
</channel>
</rss>

