鍍金池/ 問(wèn)答/HTML/ 關(guān)于ES6嚴(yán)格標(biāo)準(zhǔn)回調(diào)報(bào)錯(cuò)問(wèn)題

關(guān)于ES6嚴(yán)格標(biāo)準(zhǔn)回調(diào)報(bào)錯(cuò)問(wèn)題

  var load = function (protocol, domains, path, query, cb) {
    var tryRequest = function (at) {
      var url = makeURL(protocol, domains[at], path, query)
      loadScript(url, function (err) {
        if (err) {
          if (at >= domains.length - 1) {
            cb(true)  //https://google.com/#q=standard%2Fno-callback-literal  Unexpected literal in error position of callback
          } else {
            tryRequest(at + 1)
          }
        } else {
          cb(false)  //https://google.com/#q=standard%2Fno-callback-literal  Unexpected literal in error position of callback
        }
      })
    }
    tryRequest(0)
  }

https://github.com/standard/s...
從這里我看到了callback(true)或callback(false)在ES6里是不被允許的,這上面的代碼是由JS上改寫(xiě)的,應(yīng)該怎樣寫(xiě)才能符合ES6標(biāo)準(zhǔn)?

回答
編輯回答
舊螢火

這個(gè)不是es6的標(biāo)準(zhǔn)吧 只是這個(gè)js代碼規(guī)范框架的作者提出的一個(gè)新功能吧

2018年1月1日 18:51
編輯回答
悶油瓶

這是 eslint 的 standard 標(biāo)準(zhǔn)不允許的寫(xiě)法。
如果非要這么寫(xiě),你可以在 .eslintrc.js文件里的 rules 對(duì)象里配置來(lái)忽略這條規(guī)則。
no-callback-literal: 0

2017年12月15日 01:42