Skip to content

Instantly share code, notes, and snippets.

@hitautodestruct
Created December 23, 2021 09:06
Show Gist options
  • Save hitautodestruct/ed2be9a9f4214fef1fb024c7ba650ac3 to your computer and use it in GitHub Desktop.
Save hitautodestruct/ed2be9a9f4214fef1fb024c7ba650ac3 to your computer and use it in GitHub Desktop.
A method for recursively freezing nested objects, for use with vuex store
function deepFreeze (object) {
if (object) {
// Retrieve the property names defined on object
var propNames = Object.getOwnPropertyNames(object)
// Freeze properties before freezing self
for (let name of propNames) {
let value = object[name]
object[name] = value && typeof value === 'object' ? DataMigration.deepFreeze(value) : value
}
object = Object.freeze(object)
}
return object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment