Skip to content

Instantly share code, notes, and snippets.

@Enelar
Created July 11, 2014 05:33
Show Gist options
  • Save Enelar/34f9ef9ee412cb88beb4 to your computer and use it in GitHub Desktop.
Save Enelar/34f9ef9ee412cb88beb4 to your computer and use it in GitHub Desktop.
Emulate clone constructor in js
function CloneObject(obj)
{
if (obj === null)
return obj;
if (typeof obj !== "object")
return obj;
var copy = obj.constructor();
for (var attr in obj)
if (obj.hasOwnProperty(attr))
copy[attr] = arguments.callee(obj[attr]);
return copy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment