CoffeeScript:创建对象的浅表副本,并使用单行重命名/删除属性

时间:2015-01-27 12:36:58

标签: coffeescript

假设:

externalObject = {
  UglyKeyOne: 'val1'
  UglyKeyTwo: 'val2'
  UglyUnusedKey: 'boo'
}

有没有办法在一个班轮中进行以下2行?即创建newObject,并在一步中使用解构赋值?

{ UglyKeyOne: keyOne, UglyKeyTwo: keyTwo } = externalObject
newObject = { keyOne, keyTwo }

1 个答案:

答案 0 :(得分:1)

这有效:

newObject = { keyOne, keyTwo } = { keyOne: externalObject.UglyKeyOne, keyTwo: externalObject.UglyKeyTwo }