Created
July 11, 2014 05:33
-
-
Save Enelar/34f9ef9ee412cb88beb4 to your computer and use it in GitHub Desktop.
Emulate clone constructor in js
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 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