小编Dor*_*val的帖子

如何在浏览器中使用UMD而不需要任何其他依赖项

假设我有一个这样的UMD模块(保存在'js/mymodule.js'中):

(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ?     factory(exports) :
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
  (factory((global.mymodule = global.mymodule || {})));
}(this, function (exports) { 'use strict';
    function myFunction() {
        console.log('hello world');
    }
}));
Run Code Online (Sandbox Code Playgroud)

如何在这样的HTML文件中使用此模块?(没有requirejs,commonjs,systemjs等......)

<!doctype html>
<html>
<head>
    <title>Using MyModule</title>
    <script src="js/mymodule.js"></script>
</head>
<body>
<script>
/* HOW TO USE myFunction from mymodule.js ??? */
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助.

html javascript commonjs requirejs systemjs

17
推荐指数
4
解决办法
7979
查看次数

标签 统计

commonjs ×1

html ×1

javascript ×1

requirejs ×1

systemjs ×1