Replies: 8 comments 6 replies
-
建议去 https://es.discourse.group 发个帖子,问问有没有支持你的想法。 我个人觉得这个语法设计不妥(这个 use case 过于单一) |
Beta Was this translation helpful? Give feedback.
-
假如有一个 Object.pick(功能与 lodash.pick 一样)和这个相比哪种会更好? |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
对,我指的就是这个提案 |
Beta Was this translation helpful? Give feedback.
-
语法的门槛比较高,但语法一般比api要好用(本例中也是如此),而且有更好的性能优化。 已经有一些类似的增强对象语法的提案,所以我觉得这个主意还是可以尝试的。 |
Beta Was this translation helpful? Give feedback.
-
// 楼主的
const objB = { ...{ prop1, prop2, prop3 } = objA }
// 楼主的
const objB = { ...objA { prop1, prop2, prop3 } } // 看起来像 TS
const newObj: { prop1, prop2, prop3, ... } = oldObj
// 这也不太合适
const newObj = { prop1, prop2, prop3, ... } = oldObj
// 如果创造新符号会怎么样呢?
const newObj = oldObj -> { prop1, prop2, prop3, ...}
// or
const newObj = oldObj -> ['prop1', 'prop2', 'prop3', ...] |
Beta Was this translation helpful? Give feedback.
-
@zhenzhenChange 我倒是觉得楼主提案更好一些,为了这个加个箭头感觉有点太占用新字符了 |
Beta Was this translation helpful? Give feedback.
-
单从语法来说,也许这样是比较好的: let a = {x:1, y:2, z:3}
let b = a.{x, y}
b // {x:1, y: 2}
let c = { ...b.{x} }
c // {x:1} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
有时候会有这样的场景:有一个对象 objA 是一个很大的对象,里面有很多属性,现在需要取出其中少数几个属性存到新的对象 objB 中,代码如下:
这里会有很多重复代码,新提案是想是否可以有一个语法糖简化这个步骤,像这样:
或者:
Beta Was this translation helpful? Give feedback.
All reactions