Yah*_*iea 7 javascript node.js ecmascript-6
我正在 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)
但是,我真的想知道是否有更好的方法来做到这一点。
我真的很感谢你们的帮助!
ES6 import 语句具有声明性语法,并且不会像使用require()().
您下面的代码是唯一有效的方法。
import birds from './birds'
const SomethingButNotBirds = birds()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6473 次 |
| 最近记录: |