ESLint错误:reduce方法的prefer-arrow-callback?

时间:2017-08-18 01:12:25

标签: javascript eslint

我正在使用" prefer-arrow-method"使用下面的reduce函数抛出的eslint错误。我知道这是因为该函数是匿名的,但我如何重写reduce方法来解决此错误?

   const nameBrand =
     names.brand().reduce(function (sum, name) {
     sum[name] = name;
     return sum;
    }, {});

1 个答案:

答案 0 :(得分:2)

const nameBrand = names.brand().reduce((sum, name) => {
    sum[name] = name;
    return sum;
}, {});