Last active
December 14, 2015 02:19
-
-
Save barneycarroll/5012747 to your computer and use it in GitHub Desktop.
Quick and dirty methods for object cloning and comparison using the JSON parser
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
// Create a copy of x without reference back to x | |
function clone(x){ | |
return JSON.parse(JSON.stringify(x)); | |
} | |
// Pass any number of arguments of non-function type. Returns true if they are all identical. | |
function areEqual(){ | |
for(var i = 1, l = arguments.length, x = JSON.stringify(arguments[0]); i < arguments.length; ++i){ | |
if(x !== JSON.stringify(arguments[i])){ | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment