更多詳細(xì)內(nèi)容參考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個(gè)free variable劝评。
require函數(shù)
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對(duì)象
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對(duì)象
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對(duì)象一樣环疼。