Skip to content

Instantly share code, notes, and snippets.

@bendc
Created January 6, 2016 16:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendc/5d162a9ca711f527a4a2 to your computer and use it in GitHub Desktop.
Save bendc/5d162a9ca711f527a4a2 to your computer and use it in GitHub Desktop.
Deep freeze objects
const immutable = (() => {
const getValue = obj => key => obj[key];
const isObject = obj => Object(obj) === obj;
const isMutable = obj => isObject(obj) && !Object.isFrozen(obj);
return obj => {
Object.keys(obj).map(getValue(obj)).filter(isMutable).forEach(immutable);
return Object.freeze(obj);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment