zoukankan      html  css  js  c++  java
  • vue.js源码学习分享(一)

    今天看了vue.js源码  发现非常不错,想一边看一遍写博客和大家分享

    /**
     * Convert a value to a string that is actually rendered.
     *转换一个值为字符串 */ function _toString (val) { return val == null? '': typeof val === 'object'? JSON.stringify(val, null, 2): String(val)
    //如果该值是null则返回空字符串,如果该值为对象,则返回json字符串,否则把对象的值转化为字符串
    //知识点:JSON.stringify(val, null, 2),String(val)
    } 

      

    /**
     * Convert a input value to a number for persistence.
     * If the conversion fails, return original string.转化一个输入值为一个数字,如果转换失败,则返回原始的字符串
    */ function toNumber (val) { var n = parseFloat(val); return isNaN(n) ? val : n//判断n是不是 不是数字,如果不是数字则返回字符串,如果是则返回转换好的数字 }
    
    
    /**
    * Remove an item from an array//从数组删除一个元素
    */
    function remove (arr, item) {
    if (arr.length) {
    var index = arr.indexOf(item);//获取元素的位置
    if (index > -1) {//如果元素存在
    return arr.splice(index, 1)//从数组中删除并且返回这个元素
    }
    }
    }

    /**
    * Check whether the object has the property.//检查对象中是否有这个属性
    */
    var hasOwnProperty = Object.prototype.hasOwnProperty;//从对象的原型中获取hasOwnProperty这个方法

    function hasOwn (obj, key) {
      return hasOwnProperty.call(obj, key)
    }
     
  • 相关阅读:
    标准C程序设计七---17
    标准C程序设计七---16
    标准C程序设计七---15
    标准C程序设计七---14
    标准C程序设计七---13
    标准C程序设计七---12
    标准C程序设计七---11
    标准C程序设计七---10
    标准C程序设计七---07
    java常见文件操作
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/6669480.html
Copyright © 2011-2022 走看看