示例工程 23-esm-live-bindings
23-esm-live-bindings/02-top-level-this/main.test.mjs
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { run, topThis } from './dist/main.js';
test('模块顶层 this 是 undefined', () => {
const out = [];
const ret = run((msg) => out.push(msg));
assert.deepEqual(ret, ['topThis:undefined']);
assert.deepEqual(out, ret);
assert.equal(topThis, undefined);
});