Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active December 14, 2015 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/5012747 to your computer and use it in GitHub Desktop.
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
// 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