Created
October 28, 2019 15:17
-
-
Save leolanese/255b7dc723b4ea8d08511853f368a61e to your computer and use it in GitHub Desktop.
deepFreeze
This file contains hidden or 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
export const deepFreeze = (object: object) => { | |
const propNames = Object.getOwnPropertyNames(object); | |
for (const num of propNames) { | |
const value = object[num]; | |
object[num] = value && typeof value === 'object' ? deepFreeze(value) : value; | |
} | |
return Object.freeze(object); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment