Created
August 1, 2012 17:49
-
-
Save monolithed/3229208 to your computer and use it in GitHub Desktop.
Object.deepFreeze
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
/** | |
* 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