• avalon 中require.config源码分析


    /*********************************************************************
     *                           配置系统 
    在系统运行的开始就需要读取系统中require.config()这个方法中所配置的项目 * *********************************************************************
    */

    //这里写在前面是为了更加方便阅读代码,在实际运行中,这几段代码必须放在下面
    kernel.debug = true
    kernel.plugins = plugins
    kernel.plugins['interpolate'](["{{", "}}"])
    kernel.paths = {}
    kernel.shim = {}
    kernel.maxRepeatSize = 100
    avalon.config = kernel


    function kernel(settings) { for (var p in settings) { if (!ohasOwn.call(settings, p)) continue var val = settings[p] if (typeof kernel.plugins[p] === "function") { kernel.plugins[p](val) } else if (typeof kernel[p] === "object") { avalon.mix(kernel[p], val) } else { kernel[p] = val } } return this } var openTag, closeTag, rexpr, rexprg, rbind, rregexp = /[-.*+?^${}()|[]/\]/g function escapeRegExp(target) { //http://stevenlevithan.com/regex/xregexp/ //将字符串安全格式化为正则表达式的源码 return (target + "").replace(rregexp, "\$&") } var innerRequire = noop var plugins = { loader: function(builtin) { window.define = builtin ? innerRequire.define : otherDefine window.require = builtin ? innerRequire : otherRequire }, interpolate: function(array) { openTag = array[0] closeTag = array[1] if (openTag === closeTag) { throw new SyntaxError("openTag!==closeTag") } else if (array + "" === "<!--,-->") { kernel.commentInterpolate = true } else { var test = openTag + "test" + closeTag cinerator.innerHTML = test if (cinerator.innerHTML !== test && cinerator.innerHTML.indexOf("&lt;") > -1) { throw new SyntaxError("此定界符不合法") } cinerator.innerHTML = "" } var o = escapeRegExp(openTag), c = escapeRegExp(closeTag) rexpr = new RegExp(o + "(.*?)" + c) rexprg = new RegExp(o + "(.*?)" + c, "g") rbind = new RegExp(o + ".*?" + c + "|\sms-") } }
    just do myself
  • 相关阅读:
    Redis学习笔记之一 : 配置redis
    Web 项目更改项目名
    Linux 常用命令之一
    SQL 常用语法一
    Java http请求和调用
    Spring c3p0连接池无法释放解决方案
    Windows和Linux查看和更改mysql连接池
    Java 简单实用方法二
    Linux 更改ssh 端口
    CentOS 通过yum安装web环境
  • 原文地址:https://www.cnblogs.com/rookieCat/p/4642874.html
Copyright © 2020-2023  润新知