zoukankan      html  css  js  c++  java
  • 加载器中的预编

      if (_type == "js") {//js预编译
                        var _script = "_define(function(exports,module){
    ";
                        _script += "var $parent = "" + _basePath + "";
    ";
                        _script += data.replace(/require(/g, "_require($parent,");
                        _script += ";
    });" + "//@ sourceURL=" + _absUrl(path);
                        _moudle = window["eval"](_script);
    }

    上面这段程序会把下面的代码

    exports.txt = "hello word";
    var rep=require("./js/moule");
    module.exports={
        "name":"张三"
    }

    预编译为

    _define(function(exports,module){
    var $parent = "";
    exports.txt = "hello word";
    var rep=_require($parent,"./js/moule");
    module.exports={
        "name":"张三"
    };
    });//@ sourceURL=http://localhost:63342/jiaocheng/moudle.js

    1.加上了_define(function(exports,module){ 

    2.var rep=require("./js/moule"); 变为了var rep=_require($parent,"./js/moule");

    3.加上了var $parent = "";  $parent 是 当前js 的路径,因为 当前js在根目录 所以$parent为空

  • 相关阅读:
    线段树(已修改+补题
    畅通工程
    线段树
    charles
    flash
    mysql node pool
    node简单操作mysql的类
    小于任意数字的随机数
    文件系统的移植
    驱动
  • 原文地址:https://www.cnblogs.com/blowfish/p/3785215.html
Copyright © 2011-2022 走看看