<?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"
	>
<channel>
	<title>Comments on: Object.prototype is verboten</title>
	<atom:link href="http://erik.eae.net/archives/2005/06/06/22.13.54/feed/" rel="self" type="application/rss+xml" />
	<link>http://erik.eae.net/archives/2005/06/06/22.13.54/</link>
	<description>The Weblog of Erik Arvidsson</description>
	<pubDate>Sat, 05 Jul 2008 16:32:15 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Crossed Browser &#187; Blog Archive &#187; JavaScript Presentation Notes</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-103143</link>
		<dc:creator>Crossed Browser &#187; Blog Archive &#187; JavaScript Presentation Notes</dc:creator>
		<pubDate>Wed, 25 Jun 2008 15:42:21 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-103143</guid>
		<description>[...] of the core Javascript objects to provide &#8216;missing&#8217; functionality. Something I think should be avoided, not least because this provides forward compatibility issues. For this reason I have always been [...]</description>
		<content:encoded><![CDATA[<p>[...] of the core Javascript objects to provide &#8216;missing&#8217; functionality. Something I think should be avoided, not least because this provides forward compatibility issues. For this reason I have always been [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Multiple String Replacement Sugar</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-103121</link>
		<dc:creator>Multiple String Replacement Sugar</dc:creator>
		<pubDate>Fri, 13 Jun 2008 02:55:21 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-103121</guid>
		<description>[...] you need to worry about rouge properties that show up when people mess with Object.prototype, you can update the code as [...]</description>
		<content:encoded><![CDATA[<p>[...] you need to worry about rouge properties that show up when people mess with Object.prototype, you can update the code as [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricardo</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-103108</link>
		<dc:creator>Ricardo</dc:creator>
		<pubDate>Sun, 25 May 2008 20:08:22 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-103108</guid>
		<description>@Mike: doesn't work for me in FF 2.0.0.14, the "Hashes" still inherit from Object, as do Array/Date/etc.</description>
		<content:encoded><![CDATA[<p>@Mike: doesn&#8217;t work for me in FF 2.0.0.14, the &#8220;Hashes&#8221; still inherit from Object, as do Array/Date/etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Crossed Browser &#187; Blog Archive &#187; Rapid Client Side Development of UI Components with Base</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102946</link>
		<dc:creator>Crossed Browser &#187; Blog Archive &#187; Rapid Client Side Development of UI Components with Base</dc:creator>
		<pubDate>Tue, 19 Feb 2008 19:14:42 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102946</guid>
		<description>[...] is an attempt to bring a more classical OO nature to JavaScript, yet without the problems of polluting the core JavaScript types as in the case with the Prototype library. Javascript is an [...]</description>
		<content:encoded><![CDATA[<p>[...] is an attempt to bring a more classical OO nature to JavaScript, yet without the problems of polluting the core JavaScript types as in the case with the Prototype library. Javascript is an [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Amy</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102803</link>
		<dc:creator>Mike Amy</dc:creator>
		<pubDate>Wed, 26 Dec 2007 14:52:02 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102803</guid>
		<description>sorry, 'extends' method should have been 'extend'</description>
		<content:encoded><![CDATA[<p>sorry, &#8216;extends&#8217; method should have been &#8216;extend&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Amy</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102802</link>
		<dc:creator>Mike Amy</dc:creator>
		<pubDate>Wed, 26 Dec 2007 14:40:08 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102802</guid>
		<description>// I tried out some stuff with Firefox. If you do this:

Hash = Object;
Object = function () {return new Hash();}

/* And assuming Hash.prototype doesn't change, then:
- Hash becomes something like the root of the heirarchy.
- {} and Object() return hashes (obviously). The prototype will be empty and this cannot be overridden.
- setting Object.prototype has no effect on new Objects or {}-literal objects.

To solve the instanceof problem:

For base classes, eg Array, if you do:
*/

Function.prototype.extends = function (func) { 
    this.prototype.__proto__ = func.prototype; 
    return this; 
}
Array.extends(Object);

/* then instanceof works again:

i.e. [] instanceof Object == true;
 
You'd have to do this for the other 'classes' too, otherwise they will use the vanilla prototypes.

In addition to getting instanceof to work, overriding the Object.prototype WILL now affect arrays. So you can introduce new methods near the top of the 'class' hierarchy as well as iterating easily over Objects with for (i in obj) {...}. Best of both worlds.

I tested this in Firefox (Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1) with Venkman version 0.9.87.2.
I also tested it in Safari 3.0.4. , but not in IE.

Lastly, if you want your own new base 'class' to start your own hierarchy, i.e. start with a blank slate, it couldn't be easier, you do nothing special:

function MyObject() {};

Voila.

*/</description>
		<content:encoded><![CDATA[<p>// I tried out some stuff with Firefox. If you do this:</p>
<p>Hash = Object;<br />
Object = function () {return new Hash();}</p>
<p>/* And assuming Hash.prototype doesn&#8217;t change, then:<br />
- Hash becomes something like the root of the heirarchy.<br />
- {} and Object() return hashes (obviously). The prototype will be empty and this cannot be overridden.<br />
- setting Object.prototype has no effect on new Objects or {}-literal objects.</p>
<p>To solve the instanceof problem:</p>
<p>For base classes, eg Array, if you do:<br />
*/</p>
<p>Function.prototype.extends = function (func) {<br />
    this.prototype.__proto__ = func.prototype;<br />
    return this;<br />
}<br />
Array.extends(Object);</p>
<p>/* then instanceof works again:</p>
<p>i.e. [] instanceof Object == true;</p>
<p>You&#8217;d have to do this for the other &#8216;classes&#8217; too, otherwise they will use the vanilla prototypes.</p>
<p>In addition to getting instanceof to work, overriding the Object.prototype WILL now affect arrays. So you can introduce new methods near the top of the &#8216;class&#8217; hierarchy as well as iterating easily over Objects with for (i in obj) {&#8230;}. Best of both worlds.</p>
<p>I tested this in Firefox (Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1) with Venkman version 0.9.87.2.<br />
I also tested it in Safari 3.0.4. , but not in IE.</p>
<p>Lastly, if you want your own new base &#8216;class&#8217; to start your own hierarchy, i.e. start with a blank slate, it couldn&#8217;t be easier, you do nothing special:</p>
<p>function MyObject() {};</p>
<p>Voila.</p>
<p>*/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Amy</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102800</link>
		<dc:creator>Mike Amy</dc:creator>
		<pubDate>Tue, 25 Dec 2007 21:46:43 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102800</guid>
		<description>OK, I missed post number 56, and only tested my example in Safari 3.0.4 and 2.0.4.

But as far as I can see from post 56, unless any third party script you then include uses the unusual ({}).prototype.property = ...  

instead of the far more common 

Object.prototype.property = ... 

to override the base class, it should still work. You basically make the root class {}.
Still the problems of inheritance testing remain (even though testing for inheritance from Object seems strange as it should always be true)</description>
		<content:encoded><![CDATA[<p>OK, I missed post number 56, and only tested my example in Safari 3.0.4 and 2.0.4.</p>
<p>But as far as I can see from post 56, unless any third party script you then include uses the unusual ({}).prototype.property = &#8230;  </p>
<p>instead of the far more common </p>
<p>Object.prototype.property = &#8230; </p>
<p>to override the base class, it should still work. You basically make the root class {}.<br />
Still the problems of inheritance testing remain (even though testing for inheritance from Object seems strange as it should always be true)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Amy</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102799</link>
		<dc:creator>Mike Amy</dc:creator>
		<pubDate>Tue, 25 Dec 2007 21:22:30 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102799</guid>
		<description>// How about this simple solution: ban the b**tards from fiddling with your {}!
// running this bit of code before anything else pulls the carpet from under their feet:

var BaseObject = Object;
Object = function () { return new BaseObject(); }

// what this does is separate the {} prototype from the Object prototype. 
// However calling new Object() returns what you'd expect.

Object.prototype.x = 5;

var a = {a:1,b:2,c:3};
var s = '';
for (i in a)
s+=a[i];

// s is now '123', not '1235'
// I know there are other problems with this eg: 

[] instanceof Object == false; // it used to be true.

// Can anyone suggest how can we deal with this?
// Mike Amy</description>
		<content:encoded><![CDATA[<p>// How about this simple solution: ban the b**tards from fiddling with your {}!<br />
// running this bit of code before anything else pulls the carpet from under their feet:</p>
<p>var BaseObject = Object;<br />
Object = function () { return new BaseObject(); }</p>
<p>// what this does is separate the {} prototype from the Object prototype.<br />
// However calling new Object() returns what you&#8217;d expect.</p>
<p>Object.prototype.x = 5;</p>
<p>var a = {a:1,b:2,c:3};<br />
var s = &#8221;;<br />
for (i in a)<br />
s+=a[i];</p>
<p>// s is now &#8216;123&#8242;, not &#8216;1235&#8242;<br />
// I know there are other problems with this eg: </p>
<p>[] instanceof Object == false; // it used to be true.</p>
<p>// Can anyone suggest how can we deal with this?<br />
// Mike Amy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: coolpositive</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102589</link>
		<dc:creator>coolpositive</dc:creator>
		<pubDate>Thu, 18 Oct 2007 06:29:10 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102589</guid>
		<description>couple typos above but I just tried it out and it works. you can probably copy/paste this into a file and try if you like:

Object.prototype.each = function(func, args) {
for (property in this) {
if (!(typeof(this))[property]) {
func(property, this[property], args);
}
}
};

var x = {a:”a”, b:”b”, c:”c”};
x.each(function(property, value) {
alert(’property name ‘+property+’, value: ‘+value);
});</description>
		<content:encoded><![CDATA[<p>couple typos above but I just tried it out and it works. you can probably copy/paste this into a file and try if you like:</p>
<p>Object.prototype.each = function(func, args) {<br />
for (property in this) {<br />
if (!(typeof(this))[property]) {<br />
func(property, this[property], args);<br />
}<br />
}<br />
};</p>
<p>var x = {a:”a”, b:”b”, c:”c”};<br />
x.each(function(property, value) {<br />
alert(’property name ‘+property+’, value: ‘+value);<br />
});</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: coolpositive</title>
		<link>http://erik.eae.net/archives/2005/06/06/22.13.54/#comment-102588</link>
		<dc:creator>coolpositive</dc:creator>
		<pubDate>Thu, 18 Oct 2007 06:28:17 +0000</pubDate>
		<guid isPermaLink="false">http://erik.eae.net/archives/2005/06/06/22.08.31/#comment-102588</guid>
		<description>Here is how to do this in prototypejs fashion.

Object.extend(String.prototype, {

trim: function(){
return this.replace(/^\s+&#124;\s+$/g, ”);
}
});</description>
		<content:encoded><![CDATA[<p>Here is how to do this in prototypejs fashion.</p>
<p>Object.extend(String.prototype, {</p>
<p>trim: function(){<br />
return this.replace(/^\s+|\s+$/g, ”);<br />
}<br />
});</p>
]]></content:encoded>
	</item>
</channel>
</rss>
