“!”是什么意思?字符在nodejs模块名称中做什么?
What does the "!" character do in nodejs module names?
我已经开始使用 intern 库在 js 中编写功能测试,我意识到我无法理解这种语法:
var assert = require('intern/chai!assert');
var registerSuite = require('intern!object');
require()
方法的参数中 !
字符的用途是什么?
我从这个 similiar question and very well explained by explunit:
中为您提取了这个答案
The exclamation point syntax is reserved for plugins. Typically there would be something else following the exclamation point which indicates the resource that the plugin would load, e.g. text!myTemplate.html, but in the case of domReady! the plugin exists just as a way to wait until DOM loaded before invoking your callback function, so nothing needs to follow the exclamation point.
简答
它标识属于插件一部分的资源。
标识符的结构为:[plugin]![resource]
.
长答案
在documentation中,您可以发现:
Intern is built on top of a standard amd loader, which means that its modules are also normally written in the AMD module format.
这就是为什么以及如何实际注入 require
函数,所以很明显您没有使用随 Node.JS[= 一起提供的 require
模块56=].
它还指出:
[AMD format] Allows modules and other assets to be asynchronously or conditionally resolved by writing simple loader plugins
如果您在引用加载程序时遵循文档提供的 link,您会发现:
Loader plugins extend an AMD implementation by allowing loading of resources that are not traditional JavaScript dependencies.
特别是,您可以发现依赖项具有以下形式:
[Plugin Module ID]![resource ID]
不言而喻,使用 intern 获得的 loader 的默认实现符合上述标准。
也就是说,如果我们考虑:
intern/chai!assert
您可以将其阅读为 inter/chai
作为插件模块和 assert
作为实际需要的资源。
! 字符在 require()
方法的参数中的目的是满足用于标识资源的语法要求,该资源本身是一个插件。
我已经开始使用 intern 库在 js 中编写功能测试,我意识到我无法理解这种语法:
var assert = require('intern/chai!assert');
var registerSuite = require('intern!object');
require()
方法的参数中 !
字符的用途是什么?
我从这个 similiar question and very well explained by explunit:
中为您提取了这个答案The exclamation point syntax is reserved for plugins. Typically there would be something else following the exclamation point which indicates the resource that the plugin would load, e.g. text!myTemplate.html, but in the case of domReady! the plugin exists just as a way to wait until DOM loaded before invoking your callback function, so nothing needs to follow the exclamation point.
简答
它标识属于插件一部分的资源。
标识符的结构为:[plugin]![resource]
.
长答案
在documentation中,您可以发现:
Intern is built on top of a standard amd loader, which means that its modules are also normally written in the AMD module format.
这就是为什么以及如何实际注入 require
函数,所以很明显您没有使用随 Node.JS[= 一起提供的 require
模块56=].
它还指出:
[AMD format] Allows modules and other assets to be asynchronously or conditionally resolved by writing simple loader plugins
如果您在引用加载程序时遵循文档提供的 link,您会发现:
Loader plugins extend an AMD implementation by allowing loading of resources that are not traditional JavaScript dependencies.
特别是,您可以发现依赖项具有以下形式:
[Plugin Module ID]![resource ID]
不言而喻,使用 intern 获得的 loader 的默认实现符合上述标准。
也就是说,如果我们考虑:
intern/chai!assert
您可以将其阅读为 inter/chai
作为插件模块和 assert
作为实际需要的资源。
! 字符在 require()
方法的参数中的目的是满足用于标识资源的语法要求,该资源本身是一个插件。