0

I see a lot of node librairies using this syntax:

var lib = require('lib')();

I was wondering what was the ES6 equivalent ?

For now, I use the following syntax:

import libfunc from 'lib';
var lib = libfunc();

Is there a more elegant way to perform this import ?

bguyl
  • 332
  • 2
  • 10
  • 1
    Nope, you cannot make it shorter. – zerkms May 18 '17 at 08:12
  • Although I try to use the ES6 syntax where I can, I still stay with require like this: "const React = require('react');". But as far as I know, "import" is the ES6 equivalent of require. – Apfelbox May 18 '17 at 08:13
  • @Apfelbox `require` is a nodejs-specific function. `import` is a part of the standard. – zerkms May 18 '17 at 08:15
  • Too bad, thanks for the answer @zerkms ! – bguyl May 18 '17 at 08:18
  • @zerkms yes, you're 100% right. I was just thinking that It is possible to use import instead (even in node libraries) - my bad sorry – Apfelbox May 18 '17 at 08:20

0 Answers0