Pass options to ES6 module imports

后端 未结 7 1397
[愿得一人]
[愿得一人] 2020-11-22 04:43

Is it possible to pass options to ES6 imports?

How do you translate this:

var x = require(\'module\')(someoptions);

to ES6?

7条回答
  •  天命终不由人
    2020-11-22 05:28

    Building on @Bergi's answer to use the debug module using es6 would be the following

    // original
    var debug = require('debug')('http');
    
    // ES6
    import * as Debug from 'debug';
    const debug = Debug('http');
    
    // Use in your code as normal
    debug('Hello World!');
    

提交回复
热议问题