Skip to content

Instantly share code, notes, and snippets.

@aarongustafson
Created December 7, 2009 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarongustafson/250519 to your computer and use it in GitHub Desktop.
Save aarongustafson/250519 to your computer and use it in GitHub Desktop.
function clone( obj )
{
function F(){}
F.prototype = obj;
return new F();
};
// See http://docs.jquery.com/Utilities/jQuery.extend
function clone( obj, deep )
{
deep = deep || false;
return deep ? jQuery.extend( true, {}, obj )
: jQuery.extend( {}, obj );
}
// Source: http://keithdevens.com/weblog/archive/2007/Jun/07/javascript.clone
function clone(obj){
if ( obj == null ||
typeof(obj) != 'object') { return obj; }
var temp = new obj.constructor();
for ( var key in obj )
{
temp[key] = clone( obj[key] );
}
return temp;
}
YUI().use('json',function(Y){
function clone( obj )
{
return Y.JSON.parse( Y.JSON.stringify( obj ) );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment