Permalink
Browse files

Add Object.deepFreeze

  • Loading branch information...
0 parents commit ab6460083e195e861435b82ed354c7a0236f7182 @kangax committed Aug 17, 2010
Showing with 12 additions and 0 deletions.
  1. +12 −0 deepFreeze.js
@@ -0,0 +1,12 @@
+Object.deepFreeze = function(obj) {
+ var ownPropertyNames = Object.getOwnPropertyNames(obj),
+ i = ownPropertyNames.length,
+ ownProperty;
+ Object.freeze(obj);
+ while (i--) {
+ ownProperty = obj[ownPropertyNames[i]];
+ if (ownProperty !== null && (/^(object|function)$/).test(typeof ownProperty)) {
+ Object.deepFreeze(ownProperty);
+ }
+ }
+};

0 comments on commit ab64600

Please sign in to comment.