Any performance benefit to “locking down” JavaScript objects?

后端 未结 6 1972
Happy的楠姐
Happy的楠姐 2021-02-02 05:18

JavaScript 1.8.5 (ECMAScript 5) adds some interesting methods that prevent future modifications of a passed object, with varying degrees of thoroughness:

<
6条回答
  •  有刺的猬
    2021-02-02 05:40

    If you’re interested in the performance of object creation (literal vs frozen vs sealed vs Immutable.Map), I’ve created a test on jsPerf to check that out.

    So far I’ve only had the opportunity to test it in Chrome 41 and Firefox 37. In both browsers the creation of a frozen or sealed object takes about three times longer than the creation of a literal – whereas the Immutable.Map performs about 50 times worse than the literal.

提交回复
热议问题