SAPUI5 中的 javascript - 需要 JS 初始化以进行简单方法调用或如何将 "require js based" 库导入 SAP 业务对象

javascript in SAPUI5 - Require JS initialisation to simple method call or How to import "require js based" lib to SAP Business Objects

有人能告诉我如何更改 RequireJS 定义吗:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define([], factory(root));
    } else if (typeof exports === 'object') {
        module.exports = factory(root);
    } else {
        root.someVariable = factory(root);
    }
})(typeof global !== "undefined" ? global : this.window || this.global, function (root) {

    'use strict';

    var $someVariable = {},
        someAnotherVariable = 'bla bla bla',
....
var someFunction = function(someVar) {
}
...
    return $someVariable;
});

类似于:

var someVariable = callAllInsideAndReturnVariableValue(title, message);

详细。尝试将此 JS (https://github.com/dolce/iziToast/blob/master/dist/js/iziToast.js) 移动到简单的函数调用,如前所述。

或者有人知道如何在 SAP UI5 中使用此 JS?详见 SAP Design Studio(业务对象)

非常感谢您的帮助!

引入一个工厂来为其他人正确初始化你的模块代码。

  if (typeof define === 'function' && define.amd) {
    define([], factory(root)); //initialized through AMD
} else if (typeof exports === 'object') {
     module.exports = factory(root)//initialized module loader,see:  commonjs
} else {
    root.someVariable = factory(root);//initialize to windows/global
}

我找到了解决方案,这里是 post 如何将 RequireJS 库附加到 DS 组件: https://blogs.sap.com/2016/04/15/your-first-extension-part-13-includejs/

以防万一有人也需要这样的解决方案:)