请问这段代码中exports、module是什么意思?this, (function (exports) 这行代码怎么理解?

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
        typeof define === 'function' && define.amd ? define(['exports'], factory) :
            (factory((global.echarts = {})));
}(this, (function (exports) {
    'use strict';

// (1) The code `if (__DEV__) ...` can be removed by build tool.
// (2) If intend to use `__DEV__`, this module should be imported. Use a global
// variable `__DEV__` may cause that miss the declaration (see #6535), or the
// declaration is behind of the using position (for example in `Model.extent`,
// And tools like rollup can not analysis the dependency if not import).

    var dev;

// In browser
    if (typeof window !== 'undefined') {`请输入代码`
        dev = window.__DEV__;
    }
// In node
    else if (typeof global !== 'undefined') {
        dev = global.__DEV__;
    }

    if (typeof dev === 'undefined') {
        dev = true;
    }

    var __DEV__ = dev;
}
阅读 5.7k
2 个回答

1.这段代码应该是umd的写法,就是检测当前的运行环境支持哪种模块化规范,exports是commonjs规范,define是amd规范的写法
2.this在这里是指调用的全局环境

参考http://blog.csdn.net/Real_Bir...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题