Last active
August 29, 2015 14:18
-
-
Save OzieWest/654453d107e8f4b08c10 to your computer and use it in GitHub Desktop.
JavaScript clone function
This file contains hidden or 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) { | |
| if(obj == null || typeof(obj) != 'object') | |
| return obj; | |
| var temp = obj.constructor(); | |
| for(var key in obj) { | |
| if(obj.hasOwnProperty(key)) { | |
| temp[key] = clone(obj[key]); | |
| } | |
| } | |
| return temp; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment