syntheticModule.setExport(name, value)
版本历史
| 版本 | 变更 |
|---|---|
| v24.8.0 | 调用此方法之前不再需要调用 |
| v13.0.0, v12.16.0 | 新增于: v13.0.0, v12.16.0 |
-
name<string> 要设置的导出名称。\
name<string> Name of the export to set. -
value<any> 将导出设置为的值。\
value<any> The value to set the export to.
此方法使用给定值设置模块的导出绑定槽。
\This method sets the module export binding slots with the given value.
import vm from 'node:vm'; const m = new vm.SyntheticModule(['x'], () => { m.setExport('x', 1); }); await m.evaluate(); assert.strictEqual(m.namespace.x, 1);const vm = require('node:vm'); (async () => { const m = new vm.SyntheticModule(['x'], () => { m.setExport('x', 1); }); await m.evaluate(); assert.strictEqual(m.namespace.x, 1); })();