Created
September 18, 2017 05:33
-
-
Save pirate/a401dffd8e4b03c769da58c1f494ac2d to your computer and use it in GitHub Desktop.
This file contains 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
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