'Freezing' Arrays in Javascript?

前端 未结 3 960
轻奢々
轻奢々 2021-01-01 08:24

Since the ECMA-262 specifications Javascript has gained the Object.freeze() method, which allows for objects, whose properties can not be changed, added or removed.

3条回答
  •  滥情空心
    2021-01-01 09:21

    Instead of freeze, use spread operator to copy things without modifying them (if you are using a transpiler, of course):

    const second = {
      ...first,
      test: 20
    }
    

提交回复
热议问题