Free Variable

更多详细内容参考http://www.cnblogs.com/hongchenok/p/3685677.html

If a name is bound in a block, it is a local variable of that block. If a name is bound at the module level, it is a global variable. (The variables of the module code block are local and global.) If a variable is used in a code block but not defined there, it is a free variable.

例如,在CMD模块定义中,如下代码

define(function(require, exports, module) {
  // The module code goes here

});

其中require、exports、module就是3个free variable。
require函数
require is a function
require accepts a module identifier.
require returns the exported API of the foreign module.
If requested module cannot be returned, require should return null.

require.async is a function
require.async accepts a list of module identifiers and a optional callback function.
The callback function receives module exports as function arguments, listed in the same order as the order in the first argument.
If requested module cannot be returned, the callback should receive null correspondingly.

exports对象
In a module, there is a free variable called "exports", that is an object that the module may add its API to as it executes.

module对象
module.uri

The full resolved uri to the module.

module.dependencies

A list of module identifiers that required by the module.

module.exports

模块暴露的API,和exports对象一样。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 九十多岁的爷爷昨天去世了,剩下奶奶也九十了,叔叔们还在拼命赚钱给下一代买房,还有看孩子,无暇顾及奶奶,所以...
    木子默阅读 1,846评论 0 0
  • 卡之家小编接下里为您分享那些逆天的熊孩子们的世界,笑点低的勿进喔!现在的熊孩子们真是越来越逆天了,上小学开始传的纸...
    卡之家阅读 1,499评论 0 0
  • 每天在公司,听到同事讲到最多的是:今晚吃什么呢?明天带什么菜呢?或许这是很多上班族都会烦恼的~即使叫外卖,也会纠结...
    王小妞61阅读 3,751评论 0 6
  • 清晨,我喜欢在诺大的操场,迎着朝阳,开启新的章程。漫步在跑道上,耳边传来鸟儿清脆悦耳的歌声。抬头寻找,只见光秃秃的...
    淡水云烟2017阅读 937评论 0 0

友情链接更多精彩内容