<?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: 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>Javascript blog with messed up syntax inside</description>
	<lastBuildDate>Thu, 26 Jan 2012 01:38:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Gareth Heyes</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1760</link>
		<dc:creator>Gareth Heyes</dc:creator>
		<pubDate>Thu, 27 May 2010 13:59:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1760</guid>
		<description>@Tipsy Snake

That also works in IE8 :)</description>
		<content:encoded><![CDATA[<p>@Tipsy Snake</p>
<p>That also works in IE8 <img src='http://www.thespanner.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tipsy Snake</title>
		<link>http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1759</link>
		<dc:creator>Tipsy Snake</dc:creator>
		<pubDate>Mon, 24 May 2010 01:07:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.thespanner.co.uk/2008/04/10/javascript-cloning-objects/#comment-1759</guid>
		<description>So, this is nice for FF, but in Opera 10.50 still doesn&#039;t work.
But thanks to Praveen I have such idea for Opera:

function clone(o) {
    return eval(&#039;(&#039; + JSON.stringify(o) + &#039;)&#039;);
}</description>
		<content:encoded><![CDATA[<p>So, this is nice for FF, but in Opera 10.50 still doesn&#8217;t work.<br />
But thanks to Praveen I have such idea for Opera:</p>
<p>function clone(o) {<br />
    return eval(&#8216;(&#8216; + JSON.stringify(o) + &#8216;)&#8217;);<br />
}</p>
]]></content:encoded>
	</item>
	<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]) == &#039;object&#039; ? 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&#039;s browser independent solution with the JSON library:
&lt;pre lang=&quot;javascript&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/javascript/includes/json2.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
JSON.clone = function (obj) {
  return JSON.parse( JSON.stringify( obj ) );
};

var obj = { &quot;date&quot;: &quot;2009-03-05&quot;, &quot;amount&quot;: &quot;0.1&quot; };
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&#039;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 &amp; c++ &#039;s book ?
Post my E-mail,thank you</description>
		<content:encoded><![CDATA[<p>Have you not about c &amp; c++ &#8216;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>
</channel>
</rss>

