美文网首页
类型判断

类型判断

作者: 曼少女 | 来源:发表于2020-07-16 12:06 被阅读0次
    /*
      判断数据类型
      @param s {Object Number Function Symbol} 所有数据类型
      return string 类型
    */
    const typeArr = ['Array', 'Undefined', 'Boolean', 'Number', 'Function', 'Symbol', 'Object', 'Date', 'Window', 'String', 'RegExp']
    export const type = s => Object.prototype.toString.call(s).slice(8, -1).toLowerCase()
    /*
      isArray()
      isUndefined()
      isBoolean()
      isNumber()
      isFunction()
      isSymbol()
      isObject()
      isDate()
      isWindow()
      isString()
      isRegExp()
      return 返回boolean类型
    */
    typeArr.forEach((v) => {
      type[`is${v}`] = s => { return type(s) === v.toLowerCase() }
    })
    
    

    相关文章

      网友评论

          本文标题:类型判断

          本文链接:https://www.haomeiwen.com/subject/oolphktx.html