# 类型处理

# 目录结构

  |-- src
  |--  |-- utils
  |--  |--  |   |--type.js
1
2
3

# 实现 (opens new window)

  const toString = Object.prototype.toString

  export function isFunction (obj) {
    return typeof (obj) === 'function'
  }

  export function isObject (obj) {
    return obj === Object(obj)
  }

  export function isArray (obj) {
    return toString.call(obj) === '[object Array]'
  }

  export function isDate (obj) {
    return toString.call(obj) === '[object Date]'
  }

  export function isRegExp (obj) {
    return toString.call(obj) === '[object RegExp]'
  }
  export function isBoolean (obj) {
    return toString.call(obj) === '[object Boolean]'
  }

  export function isNumberical (obj) {
    return (typeof (obj) === 'number' || typeof (obj) === 'string') && !isNaN(obj - parseFloat(obj))
  }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
最后更新时间: 12/6/2020, 7:51:40 PM