sourceTextModule.linkRequests(modules)
-
modules
<vm.Module[]> 此模块所依赖的vm.Module
对象数组。数组中模块的顺序即为sourceTextModule.moduleRequests
的顺序。¥
modules
<vm.Module[]> Array ofvm.Module
objects that this module depends on. The order of the modules in the array is the order ofsourceTextModule.moduleRequests
. -
返回:<undefined>
¥Returns: <undefined>
链接模块依赖。此方法必须在求值前调用,并且每个模块只能调用一次。
¥Link module dependencies. This method must be called before evaluation, and can only be called once per module.
modules
数组中模块实例的顺序应与正在解析的 sourceTextModule.moduleRequests
的顺序相对应。如果两个模块请求具有相同的说明符和导入属性,则必须使用相同的模块实例解析它们,否则将抛出 ERR_MODULE_LINK_MISMATCH
错误。例如,在链接此模块的请求时:
¥The order of the module instances in the modules
array should correspond to the order of
sourceTextModule.moduleRequests
being resolved. If two module requests have the same
specifier and import attributes, they must be resolved with the same module instance or an
ERR_MODULE_LINK_MISMATCH
would be thrown. For example, when linking requests for this
module:
import foo from 'foo';
import source Foo from 'foo';
modules
数组必须包含对同一实例的两个引用,因为两个模块请求相同,但分为两个阶段。
¥The modules
array must contain two references to the same instance, because the two
module requests are identical but in two phases.
如果模块没有依赖,则 modules
数组可以为空。
¥If the module has no dependencies, the modules
array can be empty.
用户可以使用 sourceTextModule.moduleRequests
实现 ECMAScript 规范中宿主定义的 HostLoadImportedModule 抽象操作,并使用 sourceTextModule.linkRequests()
调用规范定义的 FinishLoadingImportedModule,批量处理包含所有依赖的模块。
¥Users can use sourceTextModule.moduleRequests
to implement the host-defined
HostLoadImportedModule abstract operation in the ECMAScript specification,
and using sourceTextModule.linkRequests()
to invoke specification defined
FinishLoadingImportedModule, on the module with all dependencies in a batch.
依赖的解析是同步的还是异步的由 SourceTextModule
的创建者决定。
¥It's up to the creator of the SourceTextModule
to determine if the resolution
of the dependencies is synchronous or asynchronous.
链接 modules
数组中的每个模块后,调用 sourceTextModule.instantiate()
。
¥After each module in the modules
array is linked, call
sourceTextModule.instantiate()
.