Difference between freeze and seal

后端 未结 8 992
孤独总比滥情好
孤独总比滥情好 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:09

    I wrote a test project which compares these 3 methods:

    • Object.freeze()
    • Object.seal()
    • Object.preventExtensions()

    My unit tests cover CRUD cases:

    • [C] add new property
    • [R] read existed property
    • [U] modify existed property
    • [D] remove existed property

    Result:

提交回复
热议问题