https://github.com/jsdf/deep-freeze
recursively Object.freeze() on objects and functions
https://github.com/jsdf/deep-freeze
Last synced: about 1 year ago
JSON representation
recursively Object.freeze() on objects and functions
- Host: GitHub
- URL: https://github.com/jsdf/deep-freeze
- Owner: jsdf
- License: other
- Created: 2014-09-26T01:22:13.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-02-22T23:30:50.000Z (over 9 years ago)
- Last Synced: 2025-03-30T04:09:32.439Z (about 1 year ago)
- Language: JavaScript
- Size: 165 KB
- Stars: 32
- Watchers: 3
- Forks: 49
- Open Issues: 3
-
Metadata Files:
- Readme: readme.markdown
- License: LICENSE
Awesome Lists containing this project
README
# deep-freeze-strict
recursively `Object.freeze()` objects.
this fork works in strict mode, so when
freezing a function you don't get the error:
```
> (function(){ "use strict"; deepFreeze(function(){}); })();
TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
```
# example
``` js
var deepFreeze = require('deep-freeze-strict');
deepFreeze(Buffer);
Buffer.x = 5;
console.log(Buffer.x === undefined);
Buffer.prototype.z = 3;
console.log(Buffer.prototype.z === undefined);
```
***
```
$ node example/deep.js
true
true
```
# methods
``` js
var deepFreeze = require('deep-freeze-strict')
```
## deepFreeze(obj)
Call `Object.freeze(obj)` recursively on all unfrozen properties of `obj` that
are functions or objects.
# license
public domain
Based in part on the code snippet from
[the MDN wiki page on Object.freeze()](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/freeze),
which
[is released to the public domain](https://developer.mozilla.org/en-US/docs/Project:Copyrights).