Difference between freeze and seal

后端 未结 8 974
孤独总比滥情好
孤独总比滥情好 2020-12-07 08:00

I just heard about the JavaScript methods freeze and seal, which can be used to make any Object immutable.

Here\'s a short example how to u

相关标签:
8条回答
  • 2020-12-07 08:27

    You can always looks these up in MDN. In short:

    • Freeze: makes the object immutable, meaning no change to defined property allowed, unless they are objects.
    • Seal: prevent addition of properties, however defined properties still can be changed.
    0 讨论(0)
  • 2020-12-07 08:28

    I know I may be little late but

    • Similarity: both of them are used for creating non extensible objects.
    • Difference : In Freeze configurable , enumerable and writable attributes of the object are set to false. where as in Sealed writable attribute is set to true and rest of the attributes are false.
    0 讨论(0)
提交回复
热议问题