0

如果执行数千次,解构参数会导致效率低下吗?

我想知道在反应应用程序中解构我的论点是否有效。许多层中的许多对象都有许多循环。解构如何使用 javascripts 通过引用传递?

为了测试这个写了一些咖啡。为什么在运行测试功能之前更新原始内容?

  original =
    one:
      one: 1
    two: 2

  test = ({one, two}) ->
    one.two = two
    {one,two}

  console.log original # original.one has already beed updated!! see mu's comment. 

  destructured = test original

  console.log destructured is original, original.one is destructured.one
  # false true



{
  "one": {
    "one": 1,
    "two": 2
  },
  "two": 2
}

解构似乎是通过引用传递的。如果每次反应重新渲染时多次执行,这是否有效?

编辑: mu 在评论中很好地回答了意想不到的结果。关于解构是一种好的做法的问题就是问题所在。

4

0 回答 0