【问题标题】:ESLint prefer-reflect errorESLint 首选反射错误
【发布时间】:2017-02-01 02:25:47
【问题描述】:

我遇到了 ESLint 问题

这是我的功能:

test(e) {
    const target = [].slice.call(e.target.parentNode.children).indexOf(e.target)
    this.goToItem(target)
}

这是 ESLint 告诉我的:

避免使用 Function.prototype.call,而是使用 Reflect.apply

我试图找到一些东西来帮助我进入文档 http://eslint.org/docs/rules/prefer-reflect 。但是我不知道在哪里放切片...

请问如何解决这个错误?

【问题讨论】:

  • 其实,为什么不直接Array.from(e.target.parentNode.children)呢?更清晰。
  • 您链接到的页面显示了大量如何使用 Reflect 的示例。

标签: javascript ecmascript-6 eslint


【解决方案1】:

Reflect.apply() 上的The MDN page 为您提供有关如何使用它的更多信息:

test(e) {
    const target = Reflect.apply([].slice, e.target.parentNode.children, []).indexOf(e.target)
    this.goToItem(target)
}

【讨论】:

    猜你喜欢
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-23
    • 2020-08-21
    相关资源
    最近更新 更多