美文网首页
Free Variable

Free Variable

作者: JasonQiao | 来源:发表于2016-11-08 10:26 被阅读24次

    更多详细内容参考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对象一样。

    相关文章

      网友评论

          本文标题:Free Variable

          本文链接:https://www.haomeiwen.com/subject/wtsauttx.html