码迷,mamicode.com
首页 > 其他好文 > 详细

avalon 中require.config源码分析

时间:2015-07-13 15:34:10      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

/*********************************************************************
 *                           配置系统 
在系统运行的开始就需要读取系统中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-") } }

 

avalon 中require.config源码分析

标签:

原文地址:http://www.cnblogs.com/rookieCat/p/4642874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!