基本信息
源码名称:js模块化加载展示例子下载(require module)
源码大小:3.15KB
文件格式:.zip
开发语言:js
更新时间:2016-01-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
按需加载网页模块

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="myRequire.js"></script>
</head>
<body>
    
<script>
define("math", function(require, module, exports){
    var max = function () {
        //  将参数修改为数组
        var arr = [].slice.call(arguments);
        var max = arr[0];
        arr.forEach(function(item){
            if(max < item){
                max = item;
            }
        });
        return max;
    };
    console.log('math.js');
    
    module.exports = {
        sqrt: function(n) {
            return n * n;
        },
        max: max
    };
});
define('test', function(require, module, exports){
    console.log( 'require before' );
    
    var _Math = require('math');
    console.log( _Math.sqrt(15) );
});
require('test');
</script>

</body>
</html>