ES6 导入的定义执行顺序是什么? [英] What is the defined execution order of ES6 imports?

查看:22
本文介绍了ES6 导入的定义执行顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在互联网上搜索导入模块的执行顺序.例如,假设我有以下代码:

I've tried searching the internet for the execution order of imported modules. For instance, let's say I have the following code:

import "one"
import "two"
console.log("three");

其中one.jstwo.js的定义如下:

// one.js
console.log("one");

// two.js
console.log("two");

控制台输出是否保证:

one
two
three

还是未定义?

推荐答案

JavaScript 模块被异步评估.但是,所有导入都会在模块主体进行导入之前进行评估.这使得 JavaScript 模块不同于 Node 中的常见JS 模块

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆