vm.SyntheticModule 类
稳定性: 1 - 实验
- 继承自: <vm.Module>
vm.SyntheticModule
类提供了 WebIDL 规范中定义的合成模块记录。
合成模块的目的是提供通用的接口,用于将非 JavaScript 源暴露给 ECMAScript 模块图。
const vm = require('vm');
const source = '{ "a": 1 }';
const module = new vm.SyntheticModule(['default'], function() {
const obj = JSON.parse(source);
this.setExport('default', obj);
});
// 在链接中使用 `module`...
Stability: 1 - Experimental
This feature is only available with the --experimental-vm-modules
command
flag enabled.
- Extends: <vm.Module>
The vm.SyntheticModule
class provides the Synthetic Module Record as
defined in the WebIDL specification. The purpose of synthetic modules is to
provide a generic interface for exposing non-JavaScript sources to ECMAScript
module graphs.
const vm = require('vm');
const source = '{ "a": 1 }';
const module = new vm.SyntheticModule(['default'], function() {
const obj = JSON.parse(source);
this.setExport('default', obj);
});
// Use `module` in linking...