• 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 ("
    (found in " + str + ")")
      };
    }
  • 相关阅读:
    ガリレオの苦悩 攪乱す 1
    magento -- 添加中国省份列表
    magento使用google analytics
    Magento导出订单同时导出产品信息
    如何修改WAMP数据库上传文件的大小及上传时间限制
    magento插件手动下载
    Magento的价格去掉小数点
    magento首页调用最新产品
    url重写技术
    magento添加分类属性
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/6672229.html
Copyright © 2020-2023  润新知