Travis build: 313
This commit is contained in:
32
README.md
32
README.md
@ -359,6 +359,7 @@ average(1, 2, 3);
|
||||
|
||||
* [`bindAll`](#bindall)
|
||||
* [`deepClone`](#deepclone)
|
||||
* [`deepFreeze`](#deepfreeze)
|
||||
* [`defaults`](#defaults)
|
||||
* [`dig`](#dig)
|
||||
* [`equals`](#equals-)
|
||||
@ -6496,6 +6497,37 @@ const b = deepClone(a); // a !== b, a.obj !== b.obj
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### deepFreeze
|
||||
|
||||
Deep freezes an object.
|
||||
|
||||
Calls `Object.freeze(obj)` recursively on all unfrozen properties of passed object that are `instanceof` object.
|
||||
|
||||
```js
|
||||
const deepFreeze = obj =>
|
||||
Object.keys(obj).forEach(
|
||||
prop =>
|
||||
!obj[prop] instanceof Object || Object.isFrozen(obj[prop]) ? null : deepFreeze(obj[prop])
|
||||
) || Object.freeze(obj);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
'use strict';
|
||||
|
||||
const o = deepFreeze([1, [2, 3]]);
|
||||
|
||||
o[0] = 3; // not allowed
|
||||
o[1][0] = 4; // not allowed as well
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### defaults
|
||||
|
||||
Assigns default values for all properties in an object that are `undefined`.
|
||||
|
||||
Reference in New Issue
Block a user