首页 > 解决方案 > Javascript 库不返回全局变量/定义

问题描述

我只是想就我的问题寻求帮助,我有一个外部 JS 库,目前它在 html 的标签内时工作,但是当我尝试将它合并到我的工厂函数中时,你可以在网络中看到它有已读取但当您尝试使用未定义的全局变量时,全局变量为 FlowchartLayout。

这是外部 JS 库的片段,我尝试将其设为 UMD 模块

(function (root, factory) {
  if (typeof exports === 'object') {
    // CommonJS
    module.exports = factory(require('b'));
  } else if (typeof define === 'function' && define.amd) {
    // AMD
    define(['b'], function (b) {
      return (root.returnExportsGlobal = factory(b));
    });
  } else {
    // Global Variables
    root.returnExportsGlobal = factory(root.b);
  }
}(this, function (b) {
    'use strict';

    function FlowchartLayout() {
        go.Layout.call(this);
        this._angle = 90;
        this._nodeSpacing = 40; // between nodes in same layer
        this._layerSpacing = 40; // between nodes in different layers
        this._laneProperty = "lane"; // name of data property that identifies lane as a unique number or a string
        this._laneComparer = null; // function for sorting FlowchartLanes
        this._reset();
    }
    go.Diagram.inherit(FlowchartLayout, go.Layout);
        
       /*The rest of the code of FlowchartLayout*/

    return FlowchartLayout;

}));

任何帮助将不胜感激。谢谢你!

标签: javascript

解决方案


推荐阅读