鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 請問這段代碼中exports、module是什么意思?this, (functi

請問這段代碼中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;
}
回答
編輯回答
初心

1.這段代碼應(yīng)該是umd的寫法,就是檢測當(dāng)前的運行環(huán)境支持哪種模塊化規(guī)范,exports是commonjs規(guī)范,define是amd規(guī)范的寫法
2.this在這里是指調(diào)用的全局環(huán)境

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

2018年4月15日 23:11
編輯回答
逗婦乳

umd兼容處理。
可以看umd部分

2018年5月12日 21:03