Skip to content

Instantly share code, notes, and snippets.

@suissa
Created January 10, 2019 22:21
Show Gist options
  • Save suissa/4d18ac9516528a75ba034e08abddc501 to your computer and use it in GitHub Desktop.
Save suissa/4d18ac9516528a75ba034e08abddc501 to your computer and use it in GitHub Desktop.
deepFreeze MDN
module.exports = function deepFreeze (o) {
Object.freeze(o);
Object.getOwnPropertyNames(o).forEach(function (prop) {
if (o.hasOwnProperty(prop)
&& o[prop] !== null
&& (typeof o[prop] === "object" || typeof o[prop] === "function")
&& !Object.isFrozen(o[prop])) {
deepFreeze(o[prop]);
}
});
return o;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment