I was studying Asynchronous Module Definition from wiki.commonjs.org and I am wondering what is the meaning of this piece of code.
In particular, my question is:return beta.verb();
and return require("beta").verb();
have the same effect.
If not what is the difference?
我正在研究wiki.commonjs.org的异步模块定义,我想知道这段代码的含义是什么。特别是,我的问题是:return beta.verb();并返回require(“beta”)。verb();有同样的效果。如果不是有什么区别?
define("alpha", ["require", "exports", "beta"], function (require, exports, beta) {
exports.verb = function() {
return beta.verb();
//Or:
return require("beta").verb();
}
});
1 个解决方案
#1
2
beta
is already initialized to the value of require("beta")
before the callback function is called. From the definition of define
on that page:
在调用回调函数之前,beta已经初始化为require(“beta”)的值。从该页面上的define定义:
The dependencies [argument] must be resolved prior to execution of the module factory function, and the resolved values should be passed as arguments to the factory function with argument positions corresponding to index in the dependencies array
必须在执行模块工厂函数之前解析依赖[argument],并且解析的值应作为参数传递给工厂函数,其参数位置对应于依赖关系数组中的索引
#1
2
beta
is already initialized to the value of require("beta")
before the callback function is called. From the definition of define
on that page:
在调用回调函数之前,beta已经初始化为require(“beta”)的值。从该页面上的define定义:
The dependencies [argument] must be resolved prior to execution of the module factory function, and the resolved values should be passed as arguments to the factory function with argument positions corresponding to index in the dependencies array
必须在执行模块工厂函数之前解析依赖[argument],并且解析的值应作为参数传递给工厂函数,其参数位置对应于依赖关系数组中的索引