js-6 模块,webpack安装和打包编译

模块

1.模块管理引擎

AMD CMD UMD

开发一个模块管理引擎
有定义模块的module中的define,定义的模块的方法可以被其他模块使用。hd的两个方法被lesson使用,hd的return是导出,lesson的生成方法的第二个参数是导入,第三个回调函数参数hd是hd的方法对象。

    let module = (function () {
   
        const moduleList = {
   };          //模块容器,是个对象,key是模块名字,value是模块导出的方法。按名取用。

        function define(name, modules, action) {
         //名字,依赖的参数,动作


            modules.map((m, i) => {
                        //m是依賴的模塊的名字,i是模塊的下標
                // console.log(2);
                // console.log(moduleList[m]);
                modules[i] = moduleList[m];
                // console.log(3);
                // console.log(modules[i]);               //此时的modules[i]存储的是依赖模块的方法

            })
            moduleList[name] = action.apply(null, modules);    //modules是存储的是依赖模块的方法,作为参数传递给42行module.define('lesson', ["hd"], function (hd) 的 hd
            //把模块导出的方法放到模块容器中
            // console.log(1);
            // console.log(moduleList);
        }
        console.log(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值