vue.js源码学习分享(七)
var _Set; /* istanbul ignore if */ if (typeof Set !== 'undefined' && isNative(Set)) { // use native Set when available.//当本地set有效时使用set _Set = Set; } else { // a non-standard Set polyfill that only works with primitive keys.//一个不标准的set只会和一些简单的键工作 _Set = (function () { function Set () { this.set = Object.create(null); } Set.prototype.has = function has (key) { return this.set[key] === true }; Set.prototype.add = function add (key) { this.set[key] = true; }; Set.prototype.clear = function clear () { this.set = Object.create(null); }; return Set; }()); } var perf;//性能 {//代码块这是es6中的,代替了立即执行匿名函数 perf = inBrowser && window.performance;//Web Performance API允许网页访问某些函数来测量网页和Web应用程序的性能,包括 Navigation Timing API和高分辨率时间数据。 if (perf && (!perf.mark || !perf.measure)) { perf = undefined; } } /* */ var emptyObject = Object.freeze({});//冻结一个空的对象 /** * Check if a string starts with $ or _//检查一个字符串是否以$或者下划线为开头 */ function isReserved (str) { var c = (str + '').charCodeAt(0);//把参数转为字符串获取第一个字符 return c === 0x24 || c === 0x5F } /** * Define a property.//定义一个属性 */ function def (obj, key, val, enumerable) { Object.defineProperty(obj, key, {//Object.defineProperty给对象定义属性 value: val, enumerable: !!enumerable, writable: true, configurable: true }); } /** * Parse simple path.//解析简单的路径 */ var bailRE = /[^\w.$]/; function parsePath (path) { if (bailRE.test(path)) { return } else { var segments = path.split('.'); return function (obj) { for (var i = 0; i < segments.length; i++) { if (!obj) { return } obj = obj[segments[i]]; } return obj } } } var warn = noop; var tip = noop; var formatComponentName; { var hasConsole = typeof console !== 'undefined'; var classifyRE = /(?:^|[-_])(\w)/g; var classify = function (str) { return str .replace(classifyRE, function (c) { return c.toUpperCase(); }) .replace(/[-_]/g, ''); }; warn = function (msg, vm) { if (hasConsole && (!config.silent)) { console.error("[Vue warn]: " + msg + " " + ( vm ? formatLocation(formatComponentName(vm)) : '' )); } }; tip = function (msg, vm) { if (hasConsole && (!config.silent)) { console.warn("[Vue tip]: " + msg + " " + ( vm ? formatLocation(formatComponentName(vm)) : '' )); } }; formatComponentName = function (vm, includeFile) {//格式化组件名称 if (vm.$root === vm) { return '<Root>' } var name = vm._isVue ? vm.$options.name || vm.$options._componentTag : vm.name; var file = vm._isVue && vm.$options.__file; if (!name && file) { var match = file.match(/([^/\\]+)\.vue$/); name = match && match[1]; } return ( (name ? ("<" + (classify(name)) + ">") : "<Anonymous>") + (file && includeFile !== false ? (" at " + file) : '') ) }; var formatLocation = function (str) { if (str === "<Anonymous>") { str += " - use the \"name\" option for better debugging messages."; } return ("\n(found in " + str + ")") }; }
请爱好前端技术的朋友,联系我,有问题大家一起讨论