zoukankan      html  css  js  c++  java
  • Vue 源码 基础知识点

    1、数据类型判断

    const _toString = Object.prototype.toString
    
                function toRawType(value) {
                    return _toString.call(value).slice(8, -1)
                }
    console.log(toRawType({}))//Object

    2、转换为字符串

    function toString(val) {
                    return val == null ?
                        '' :
                        typeof val === 'object' ?
                        JSON.stringify(val, null, 2) :
                        String(val)
                }

    3、转换为number

    function toNumber(val) {
                    const n = parseFloat(val)
                    return isNaN(n) ? val : n
                }

    4、检测值是否已经定义

    function makemapValue(str,expectsLowerCase) {
                    const mapValue = Object.create(null)
                    const list = str.split(',')
                    for(let i = 0; i < list.length; i++) {
                        mapValue[list[i]] = true
                    }
                    return expectsLowerCase ?
                        val => mapValue[val.toLowerCase()] :
                        val => mapValue[val]
                }
                let isBuiltInTag = makemapValue('slot,component',true);
                console.log(isBuiltInTag('slot'))//true
                console.log(isBuiltInTag('abc'))//undefined
  • 相关阅读:
    zabbix:乱码问题
    zabbix--微信报警(未完成)
    ansible-playbook项目(4)
    ansible-playbook(3)
    备份和校验脚本-邮件通知
    rsync
    keepalived
    双机热备
    nginx负载均衡
    LNMP(5)
  • 原文地址:https://www.cnblogs.com/mengfangui/p/9766798.html
Copyright © 2011-2022 走看看