Skip to content

Instantly share code, notes, and snippets.

@gracefullight
Created December 22, 2016 08:25
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 gracefullight/6235e5c58f204a21073145f5f2137ce0 to your computer and use it in GitHub Desktop.
Save gracefullight/6235e5c58f204a21073145f5f2137ce0 to your computer and use it in GitHub Desktop.
function deepFreeze(obj){
if (!Object.isFrozen(obj)){
Object.freeze(obj);
}
for (var key in obj) {
if ({}.hasOwnProperty.call(obj, key) || !(typeof obj[key] === 'function' || typeof obj[key] === 'object' && !!obj[key])) {
continue;
}
deepFreeze(obj[key]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment