Any performance benefit to “locking down” JavaScript objects?

后端 未结 6 1995
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条回答
  •  猫巷女王i
    2021-02-02 05:32

    In theory freezing an object allows you to make stronger guarantees about the shape of an object.

    This means the VM can compact the memory size.

    It means the VM can optimize property lookups in the prototype chain.

    It means any live references just became not live because the object cannot change anymore.

    In practice JavaScript engines do not make these aggressive optimization yet.

提交回复
热议问题