【发布时间】:2018-07-20 17:55:22
【问题描述】:
在我的 React 应用程序中,我使用的是 airbnb 的 eslint 样式指南,如果我不使用解构,它将引发错误。
在下面的情况下,我首先使用let 将两个变量latitude 和longitude 分配给位置对象数组中第一项的坐标。然后,如果用户允许我访问他们的位置,我会尝试使用解构来重新分配他们的值。
let latitude = locations[0].coordinates[1];
let longitude = locations[0].coordinates[0];
if (props.userLocation.coords) {
// doesn't work - unexpected token
{ latitude, longitude } = props.userLocation.coords;
// causes linting errors
// latitude = props.userLocation.coords.latitude;
// longitude = props.userLocation.coords.longitude;
}
在if 语句中解构会导致unexpected token 错误。
以老式方式重新分配变量会导致 ESlint: Use object destructuring 错误。
【问题讨论】:
标签: javascript ecmascript-6 eslint