简体   繁体   中英

How should I handle prefer arrow callback and unnamed function code issues

I am new to ES6 and been trying to figure out how to rewrite this.

I am receiving the ff: in my eslint

  • Unexpected function expression. (prefer-arrow-callback)
  • Unexpected unnamed function. (func-names)

server.listen(config.site.port, config.site.host, function (err) { if (err) { throw err; } });

I tried reading the specs and try it out but can't seem to figure out what to do if it has if condition. https://eslint.org/docs/rules/prefer-arrow-callback

Thanks a lot.

The prefer-arrow-callback should be fixed by:

server.listen(config.site.port, config.site.host, (err) => {
   if (err) {
       throw err;
   }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM