我正在 NodeJS 上做一些事情,我正在使用importES6 语法中的关键字。我想在调用它后立即执行。我搜索了类似的想法来做到这一点,但没有任何帮助。
我想要做的基本上是将以下代码从CommonJS转换为ES6。
// In CommonJS:
var birds = require('./birds')()
// In ES6:
import birds from './birds'()
Run Code Online (Sandbox Code Playgroud)
我可以使用const关键字来做到这一点:
import birds from './birds'
const SomethingButNotBirds = birds()
Run Code Online (Sandbox Code Playgroud)
但是,我真的想知道是否有更好的方法来做到这一点。
我真的很感谢你们的帮助!