<?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: Javascript cloning objects</title>
	<atom:link href="http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/</link>
	<description>A tool for designers dealing with programmers dealing with designers...</description>
	<pubDate>Wed, 10 Mar 2010 13:34:06 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Praveen</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1625</link>
		<dc:creator>Praveen</dc:creator>
		<pubDate>Tue, 08 Sep 2009 20:26:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1625</guid>
		<description>Another implementation that worked for me.

var originalJSONObj = this.jsonPanelData.fieldList;  //fieldList is the json object being passed from server side
var clonedJSONObj = this.deepCloneJSON(originalJSONObj); //clonedJSONObj is the cloned object

deepCloneJSON: function(obj) {
	var outpurArr = new Array();
	for (var i in obj) {
		outpurArr[i] = typeof (obj[i]) == 'object' ? this.deepCloneJSON(obj[i]) : obj[i];
	}
	return outpurArr;
},</description>
		<content:encoded><![CDATA[<p>Another implementation that worked for me.</p>
<p>var originalJSONObj = this.jsonPanelData.fieldList;  //fieldList is the json object being passed from server side<br />
var clonedJSONObj = this.deepCloneJSON(originalJSONObj); //clonedJSONObj is the cloned object</p>
<p>deepCloneJSON: function(obj) {<br />
	var outpurArr = new Array();<br />
	for (var i in obj) {<br />
		outpurArr[i] = typeof (obj[i]) == &#8216;object&#8217; ? this.deepCloneJSON(obj[i]) : obj[i];<br />
	}<br />
	return outpurArr;<br />
},</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cygro</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1591</link>
		<dc:creator>cygro</dc:creator>
		<pubDate>Mon, 06 Jul 2009 09:25:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1591</guid>
		<description>Nice approach. 
Unfortunately it works only in Firefox (breaks in Chrome, Safari and IE). Therefore useless for production use (unless you can restrict access to Firefox users only)...</description>
		<content:encoded><![CDATA[<p>Nice approach.<br />
Unfortunately it works only in Firefox (breaks in Chrome, Safari and IE). Therefore useless for production use (unless you can restrict access to Firefox users only)&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: numericalexample.com</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1475</link>
		<dc:creator>numericalexample.com</dc:creator>
		<pubDate>Thu, 05 Mar 2009 10:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1475</guid>
		<description>The following function is a variant on Mikael Grave's browser independent solution with the JSON library:
&lt;pre lang="javascript"&gt;
&lt;script type="text/javascript" src="/javascript/includes/json2.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;&lt;!--
JSON.clone = function (obj) {
  return JSON.parse( JSON.stringify( obj ) );
};

var obj = { "date": "2009-03-05", "amount": "0.1" };
var clonedObj = JSON.clone(obj);
//--&gt;
&lt;/script&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>The following function is a variant on Mikael Grave&#8217;s browser independent solution with the JSON library:</p>
<pre lang="javascript">
<script type="text/javascript" src="/javascript/includes/json2.js"></script>
<script type="text/javascript"><!--
JSON.clone = function (obj) {
  return JSON.parse( JSON.stringify( obj ) );
};

var obj = { "date": "2009-03-05", "amount": "0.1" };
var clonedObj = JSON.clone(obj);
//-->
</script>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Heyes</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1459</link>
		<dc:creator>Gareth Heyes</dc:creator>
		<pubDate>Wed, 18 Feb 2009 15:26:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1459</guid>
		<description>@alex 

It's Firefox only</description>
		<content:encoded><![CDATA[<p>@alex </p>
<p>It&#8217;s Firefox only</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: alex</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1458</link>
		<dc:creator>alex</dc:creator>
		<pubDate>Wed, 18 Feb 2009 13:20:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1458</guid>
		<description>eval(uneval())
does not work for me</description>
		<content:encoded><![CDATA[<p>eval(uneval())<br />
does not work for me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mikael Grave</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1220</link>
		<dc:creator>Mikael Grave</dc:creator>
		<pubDate>Fri, 09 May 2008 17:29:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1220</guid>
		<description>Your eval/uneval idea inspired me a cross-browser solution for those using YUI:

function clone = function( obj ) {
  return YAHOO.lang.JSON.parse( YAHOO.lang.JSON.stringify( obj ) );
}

Tested fine with IE6 and FF2. Especially convenient for cloning arrays, hashs of arrays, arrays of hashs, etc.

Not sure about the performances. Might slow down your app if used to massively clone objects...</description>
		<content:encoded><![CDATA[<p>Your eval/uneval idea inspired me a cross-browser solution for those using YUI:</p>
<p>function clone = function( obj ) {<br />
  return YAHOO.lang.JSON.parse( YAHOO.lang.JSON.stringify( obj ) );<br />
}</p>
<p>Tested fine with IE6 and FF2. Especially convenient for cloning arrays, hashs of arrays, arrays of hashs, etc.</p>
<p>Not sure about the performances. Might slow down your app if used to massively clone objects&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kymin</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1205</link>
		<dc:creator>kymin</dc:creator>
		<pubDate>Sun, 20 Apr 2008 18:38:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1205</guid>
		<description>Have you not about c &#38; c++ 's book ?
Post my E-mail,thank you</description>
		<content:encoded><![CDATA[<p>Have you not about c &amp; c++ &#8217;s book ?<br />
Post my E-mail,thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Heyes</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1202</link>
		<dc:creator>Gareth Heyes</dc:creator>
		<pubDate>Thu, 10 Apr 2008 17:19:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1202</guid>
		<description>@kourge

Nice tip and good point</description>
		<content:encoded><![CDATA[<p>@kourge</p>
<p>Nice tip and good point</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kourge</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1201</link>
		<dc:creator>kourge</dc:creator>
		<pubDate>Thu, 10 Apr 2008 17:08:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1201</guid>
		<description>It is bad practice to mingle with Object.prototype because it messes up property enumeration. Just google "Object.prototype is verboten" and a zillion arguments will appear. The Prototype JavaScript library once did this in 1.3 - with bad results.
The fix is to instead tack methods on to the global Object. For example:
Object.clone = function(object) { return eval(uneval(object)); };</description>
		<content:encoded><![CDATA[<p>It is bad practice to mingle with Object.prototype because it messes up property enumeration. Just google &#8220;Object.prototype is verboten&#8221; and a zillion arguments will appear. The Prototype JavaScript library once did this in 1.3 - with bad results.<br />
The fix is to instead tack methods on to the global Object. For example:<br />
Object.clone = function(object) { return eval(uneval(object)); };</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gareth Heyes</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1200</link>
		<dc:creator>Gareth Heyes</dc:creator>
		<pubDate>Thu, 10 Apr 2008 12:43:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1200</guid>
		<description>@pdp

Damn I thought it worked in IE7 ah well neat trick anyways</description>
		<content:encoded><![CDATA[<p>@pdp</p>
<p>Damn I thought it worked in IE7 ah well neat trick anyways</p>
]]></content:encoded>
	</item>
</channel>
</rss>
