/********************************************************************* * 配置系统 * **********************************************************************/ 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') { Anot.mix(kernel[p], val) } else { kernel[p] = val } } return this } Anot.config = kernel var openTag, closeTag, rexpr, rexprg, rbind, rregexp = /[-.*+?^${}()|[\]\/\\]/g function escapeRegExp(target) { //http://stevenlevithan.com/regex/xregexp/ //将字符串安全格式化为正则表达式的源码 return (target + '').replace(rregexp, '\\$&') } var plugins = { interpolate: function(array) { openTag = array[0] closeTag = array[1] if (openTag === closeTag) { throw new SyntaxError('openTag!==closeTag') var test = openTag + 'test' + closeTag cinerator.innerHTML = test if ( cinerator.innerHTML !== test && cinerator.innerHTML.indexOf('<') > -1 ) { throw new SyntaxError('此定界符不合法') } cinerator.innerHTML = '' } kernel.openTag = openTag kernel.closeTag = closeTag var o = escapeRegExp(openTag), c = escapeRegExp(closeTag) rexpr = new RegExp(o + '([\\s\\S]*)' + c) rexprg = new RegExp(o + '([\\s\\S]*)' + c, 'g') rbind = new RegExp(o + '[\\s\\S]*' + c + '|\\s:') //此处有疑问 } } kernel.plugins = plugins kernel.plugins['interpolate'](['{{', '}}']) kernel.async = true kernel.paths = {} kernel.shim = {} kernel.maxRepeatSize = 100