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.

Revisions

  1. hitautodestruct revised this gist Dec 23, 2021. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion deepFreeze.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@ function deepFreeze (object) {
    var propNames = Object.getOwnPropertyNames(object)

    // Freeze properties before freezing self

    for (let name of propNames) {
    let value = object[name]

  2. hitautodestruct renamed this gist Dec 23, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. hitautodestruct created this gist Dec 23, 2021.
    18 changes: 18 additions & 0 deletions deepFreeze
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    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
    }