Why did ECMASCRIPT 6 reverse the sides for assignment when destructuring? [closed]

我怕爱的太早我们不能终老 提交于 2019-11-29 16:07:24

Because it is supposed to keep the object literal syntax: the property name comes before the colon. The syntax is supposed to nest, and that wouldn't work properly if the target was on the left side:

let {propName: [arrayElement, ...moreElements], otherName: {nestedProp: targetName}} = obj;

In your approach, it would be

let {[arrayElement, ...moreElements]: propName, {targetName = nestedProp}: otherName} = obj;

where the colon doesn't make any sense.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!