Node.js module.link

🌙
手机阅读
本文目录结构

Node.js module.link(linker)

  • linker < Function>
  • Returns:

Link module dependencies. This method must be called before instantiation, and can only be called once per module.

Two parameters will be passed to the linker function:

  • specifier The specifier of the requested module:
import foo from 'foo';
//              ^^^^^ the module specifier
  • referencingModule The Module object link() is called on.

The function is expected to return a Module object or a Promise that eventually resolves to a Module object. The returned Module must satisfy the following two invariants:

  • It must belong to the same context as the parent Module.
  • Its linkingStatus must not be ‘errored’.

If the returned Module’s linkingStatus is ‘unlinked’, this method will be recursively called on the returned Module with the same provided linker function.

link() returns a Promise that will either get resolved when all linking instances resolve to a valid Module, or rejected if the linker function either throws an exception or returns an invalid Module.

The linker function roughly corresponds to the implementation-defined HostResolveImportedModule abstract operation in the ECMAScript specification, with a few key differences:

  • The linker function is allowed to be asyl’pnchronous while HostResolveImportedModule is synchronous.
  • The linker function is executed during linking, a Node.js-specific stage before instantiation, while HostResolveImportedModule is called during instantiation. The actual HostResolveImportedModule implementation used during module instantiation is one that returns the modules linked during linking. Since at that point all modules would have been fully linked already, the HostResolveImportedModule implementation is fully synchronous per specification.

更多内容请参考:Node.js vm,或者通过 点击对应菜单 进行查看;



AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

目前重心已经放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>