<?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: I Object</title>
	<atom:link href="http://www.yuiblog.com/blog/index.php/2007/05/10/i-object/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yuiblog.com/blog/2007/05/10/i-object/</link>
	<description>The official blog of the YUI Project.</description>
	<lastBuildDate>Thu, 09 Feb 2012 01:46:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
	<item>
		<title>By: Neil</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-133556</link>
		<dc:creator>Neil</dc:creator>
		<pubDate>Thu, 31 May 2007 13:23:57 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-133556</guid>
		<description>hasOwnProperty can be avoided by using the following:

if(myList[word] &amp;&amp; (myList[word] !== {}[word]){
...
}

This would also allow for the myList object to inherit non-owned properties from the prototype chain.</description>
		<content:encoded><![CDATA[<p>hasOwnProperty can be avoided by using the following:</p>
<p>if(myList[word] &amp;&amp; (myList[word] !== {}[word]){<br />
&#8230;<br />
}</p>
<p>This would also allow for the myList object to inherit non-owned properties from the prototype chain.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Royer</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-113227</link>
		<dc:creator>Julien Royer</dc:creator>
		<pubDate>Sun, 13 May 2007 23:28:11 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-113227</guid>
		<description>If you use a JavaScript object as a general hash map (i.e. with undetermined keys), it is even easier to make your program fail:

var obj = {};

obj[&quot;hasOwnProperty&quot;] = &quot;coconut&quot;;

alert(obj.hasOwnProperty(&quot;a&quot;));</description>
		<content:encoded><![CDATA[<p>If you use a JavaScript object as a general hash map (i.e. with undetermined keys), it is even easier to make your program fail:</p>
<p>var obj = {};</p>
<p>obj["hasOwnProperty"] = &#8220;coconut&#8221;;</p>
<p>alert(obj.hasOwnProperty(&#8220;a&#8221;));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Douglas Crockford</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-113176</link>
		<dc:creator>Douglas Crockford</dc:creator>
		<pubDate>Sun, 13 May 2007 22:34:24 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-113176</guid>
		<description>Daniel brings up an interesting case. __proto__ is a non-standard deviation from the ECMAScript standard that can be found in the Mozilla browsers. It can cause good programs to fail.</description>
		<content:encoded><![CDATA[<p>Daniel brings up an interesting case. __proto__ is a non-standard deviation from the ECMAScript standard that can be found in the Mozilla browsers. It can cause good programs to fail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Royer</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-113175</link>
		<dc:creator>Julien Royer</dc:creator>
		<pubDate>Sun, 13 May 2007 22:34:19 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-113175</guid>
		<description>I agree with Daniel. The use of a raw abject as a general hash map in JavaScript can not be totally bulletproof.</description>
		<content:encoded><![CDATA[<p>I agree with Daniel. The use of a raw abject as a general hash map in JavaScript can not be totally bulletproof.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-112668</link>
		<dc:creator>Daniel</dc:creator>
		<pubDate>Sun, 13 May 2007 11:45:15 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-112668</guid>
		<description>hasOwnProperty isn&#039;t quite bulletproof, because on some browsers myList.hasOwnProperty(&quot;__proto__&quot;) will return true - since all objects have a __proto__ member pointing to their prototype. And then, if you then make any changes to myList[&quot;__proto__&quot;], you&#039;ll be messing with the object prototype. Nice.

Of course, &quot;__proto__&quot; doesn&#039;t turn up that often. But this can lead to odd and subtle bugs.</description>
		<content:encoded><![CDATA[<p>hasOwnProperty isn&#8217;t quite bulletproof, because on some browsers myList.hasOwnProperty(&#8220;__proto__&#8221;) will return true &#8211; since all objects have a __proto__ member pointing to their prototype. And then, if you then make any changes to myList["__proto__"], you&#8217;ll be messing with the object prototype. Nice.</p>
<p>Of course, &#8220;__proto__&#8221; doesn&#8217;t turn up that often. But this can lead to odd and subtle bugs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tino Zijdel</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-110783</link>
		<dc:creator>Tino Zijdel</dc:creator>
		<pubDate>Fri, 11 May 2007 20:26:13 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-110783</guid>
		<description>I wasn&#039;t really surprised when you started using hasOwnProperty() in json.js ;)

Although some people still consider prototyping Object &#039;verboten&#039; I do think there are some valid reasons to do so, like when you want to backport some general object methods to older browsers.

&lt;code&gt;toJSONString()&lt;/code&gt; is a good example because it will probably become a standard method in future javascript, so the only way to have the same support in older (now current) browsers will be to prototype this method on Object.

I once wrote a blogpost about that which also contains a nice snippet for browsers that do not natively support &lt;code&gt;hasOwnProperty()&lt;/code&gt; and which ironically and necessarily uses Object.prototype: &lt;a href=&quot;http://therealcrisp.xs4all.nl/blog/2006/12/04/tojsonstring-and-objectprototype/&quot; rel=&quot;nofollow&quot;&gt;.toJSONString() and Object.prototype&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>I wasn&#8217;t really surprised when you started using hasOwnProperty() in json.js ;)</p>
<p>Although some people still consider prototyping Object &#8216;verboten&#8217; I do think there are some valid reasons to do so, like when you want to backport some general object methods to older browsers.</p>
<p><code>toJSONString()</code> is a good example because it will probably become a standard method in future javascript, so the only way to have the same support in older (now current) browsers will be to prototype this method on Object.</p>
<p>I once wrote a blogpost about that which also contains a nice snippet for browsers that do not natively support <code>hasOwnProperty()</code> and which ironically and necessarily uses Object.prototype: <a href="http://therealcrisp.xs4all.nl/blog/2006/12/04/tojsonstring-and-objectprototype/" rel="nofollow">.toJSONString() and Object.prototype</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Moller</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-110664</link>
		<dc:creator>Geoff Moller</dc:creator>
		<pubDate>Fri, 11 May 2007 18:16:59 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-110664</guid>
		<description>It&#039;s always refreshing to work with a language that constantly forces you to examine it&#039;s warts in order for you work with it 
correctly. :)

It should be noted that Prototype&#039;s Ruby-inspired collection facilities (&lt;a href=&quot;http://www.prototypejs.org/api/enumerable&quot; rel=&quot;nofollow&quot;&gt;Enumerable&lt;/a&gt;, &lt;a href=&quot;http://www.prototypejs.org/api/array&quot; rel=&quot;nofollow&quot;&gt;Array&lt;/a&gt;, and &lt;a href=&quot;http://www.prototypejs.org/api/object&quot; rel=&quot;nofollow&quot;&gt;Hash&lt;/a&gt;) allow you to abstract this fact-checking to a single place. Of course, we will always have to pick our flavor of pain: the &quot;break&quot; functionality in Prototype is accomplished with a global hack. Additionally, the current uncompressed version of Prototype is now weighing in at ~ 95kb.

Ahh, sweet sweet Javascript - you are a harsh mistress.   


&lt;code&gt;
/* NOTE - console.log requires Firebug: http://www.getfirebug.com/ */

/* spits out all links&#039; hrefs and all the wonderful native goodness */
console.log(&quot;Native&quot;);
var links = document.getElementsByTagName(&#039;a&#039;);
for(var link in links){
	console.log(link + &quot;:&quot; + links[link]);
}

console.log(&quot; &quot;);

/* spits out all links&#039; hrefs */
/* REQUIRES PROTOTYPE */
console.log(&quot;Massaged&quot;);
links = $A(document.getElementsByTagName(&#039;a&#039;));
links.each(function(link){
	console.log(link.href); 
}); 
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>It&#8217;s always refreshing to work with a language that constantly forces you to examine it&#8217;s warts in order for you work with it<br />
correctly. :)</p>
<p>It should be noted that Prototype&#8217;s Ruby-inspired collection facilities (<a href="http://www.prototypejs.org/api/enumerable" rel="nofollow">Enumerable</a>, <a href="http://www.prototypejs.org/api/array" rel="nofollow">Array</a>, and <a href="http://www.prototypejs.org/api/object" rel="nofollow">Hash</a>) allow you to abstract this fact-checking to a single place. Of course, we will always have to pick our flavor of pain: the &#8220;break&#8221; functionality in Prototype is accomplished with a global hack. Additionally, the current uncompressed version of Prototype is now weighing in at ~ 95kb.</p>
<p>Ahh, sweet sweet Javascript &#8211; you are a harsh mistress.   </p>
<p><code><br />
/* NOTE - console.log requires Firebug: <a href="http://www.getfirebug.com/" rel="nofollow">http://www.getfirebug.com/</a> */</p>
<p>/* spits out all links' hrefs and all the wonderful native goodness */<br />
console.log("Native");<br />
var links = document.getElementsByTagName('a');<br />
for(var link in links){<br />
	console.log(link + ":" + links[link]);<br />
}</p>
<p>console.log(" ");</p>
<p>/* spits out all links' hrefs */<br />
/* REQUIRES PROTOTYPE */<br />
console.log("Massaged");<br />
links = $A(document.getElementsByTagName('a'));<br />
links.each(function(link){<br />
	console.log(link.href);<br />
});<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Julien Royer</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-110398</link>
		<dc:creator>Julien Royer</dc:creator>
		<pubDate>Fri, 11 May 2007 12:13:06 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-110398</guid>
		<description>@Matt : it doesn&#039;t work. For example, if keys are added to the Objet constructor after the computation of &quot;keysToIgnore&quot;.

&quot;hasOwnProperty&quot; is not supported on IE 5.</description>
		<content:encoded><![CDATA[<p>@Matt : it doesn&#8217;t work. For example, if keys are added to the Objet constructor after the computation of &#8220;keysToIgnore&#8221;.</p>
<p>&#8220;hasOwnProperty&#8221; is not supported on IE 5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Donzo</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-109907</link>
		<dc:creator>Donzo</dc:creator>
		<pubDate>Fri, 11 May 2007 00:28:35 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-109907</guid>
		<description>So, seems that using members for a purpose never intended (and arguably in a way many developers would initially find confusing) gets you into trouble.  No surprise there.  Is it the language&#039;s fault ... or the coders?</description>
		<content:encoded><![CDATA[<p>So, seems that using members for a purpose never intended (and arguably in a way many developers would initially find confusing) gets you into trouble.  No surprise there.  Is it the language&#8217;s fault &#8230; or the coders?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt</title>
		<link>http://www.yuiblog.com/blog/2007/05/10/i-object/comment-page-1/#comment-109791</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Thu, 10 May 2007 22:26:34 +0000</pubDate>
		<guid isPermaLink="false">http://yuiblog.com/blog/2007/05/10/i-object/#comment-109791</guid>
		<description>A trick I use to detect what methods have been added to Array and Object, is to include this script right after my libraries. Then any time I use the for/in I ignore these keywords.

var keysToIgnore = function() {
            var keys = [];
            var arr = [], obj = {};
            for (var k in arr) {keys.push(k);}
            for (var k in obj) {keys.push(k);}
            return keys;
        }();</description>
		<content:encoded><![CDATA[<p>A trick I use to detect what methods have been added to Array and Object, is to include this script right after my libraries. Then any time I use the for/in I ignore these keywords.</p>
<p>var keysToIgnore = function() {<br />
            var keys = [];<br />
            var arr = [], obj = {};<br />
            for (var k in arr) {keys.push(k);}<br />
            for (var k in obj) {keys.push(k);}<br />
            return keys;<br />
        }();</p>
]]></content:encoded>
	</item>
</channel>
</rss>

