Created
December 7, 2009 01:09
-
-
Save aarongustafson/250519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clone( obj ) | |
{ | |
function F(){} | |
F.prototype = obj; | |
return new F(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See http://docs.jquery.com/Utilities/jQuery.extend | |
function clone( obj, deep ) | |
{ | |
deep = deep || false; | |
return deep ? jQuery.extend( true, {}, obj ) | |
: jQuery.extend( {}, obj ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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