示例工程 13-esm
13-esm/02-top-level-this/index.html
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>13 · 模块顶层 this</title>
</head>
<body>
<p>打开 Console 对比 classic 脚本与 module 的顶层 this。</p>
<script>
// classic 脚本:顶层 this 是全局对象
console.log('classic 顶层 this === window =>', this === window);
</script>
<script type="module">
import { run } from './main.js';
run();
</script>
</body>
</html>