Skip to content

Instantly share code, notes, and snippets.

@monolithed
Created August 1, 2012 17:49
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 monolithed/3229208 to your computer and use it in GitHub Desktop.
Save monolithed/3229208 to your computer and use it in GitHub Desktop.
Object.deepFreeze
/**
* Object.deepFreeze
* Licensed under the MIT
* @author: Alexander Guinness
* @version: 1.1
* @date: Fri Jun 27 17:26:00 2011
**/
if (!Object.deepFreeze && Object.freeze && Object.isFrozen) {
Object.deepFreeze = function(object)
{
var is = Object.prototype.toString, value;
if (!object)
throw new TypeError('Object.deepFreeze: ' + object + ' is not callable!');
for (key in object)
{
value = object[key];
if (is.call(value) === '[object Object]' && Object.prototype.hasOwnProperty.call(object, key) && !Object.isFrozen(value))
Object.deepFreeze(value);
}
return Object.freeze(object);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment