Skip to content

Instantly share code, notes, and snippets.

@pirate
Created September 18, 2017 05:33
Show Gist options
  • Save pirate/a401dffd8e4b03c769da58c1f494ac2d to your computer and use it in GitHub Desktop.
Save pirate/a401dffd8e4b03c769da58c1f494ac2d to your computer and use it in GitHub Desktop.
const immutify = (obj) => {
const obj = Object.keys(obj).reduce((acc, key) => {
Object.defineProperty(acc, key, { value: obj[key], writable: false, enumerable: true})
return acc
}, {})
const hash = hashObj(obj)
Object.defineProperty(obj, 'hash', { value: hash, writable: false, enumerable: false})
Object.preventExtensions(obj)
return obj
}
const deimmutify = (obj) =>
Object.keys(obj).reduce((acc, key) => {
acc[key] = obj[key]
return acc
}, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment