# isDate

# Description

检查 value 是否是 Date 对象。

# Params

value

# Return

Boolean

# Depend

import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'
import nodeTypes from './.internal/nodeTypes.js'

getTag 源码分析

isObjectLike 源码分析

nodeTypes 源码分析

# Code

const nodeIsDate = nodeTypes && nodeTypes.isDate
const isDate = nodeIsDate
  ? (value) => nodeIsDate(value)
  : (value) => isObjectLike(value) && getTag(value) == '[object Date]'

# Analyze

isArrayBuffer 基本一致,也是判断了 node 是否可用,不可用时就通过 getTag 判断了类型

# Remark

  1. Date MDN (opens new window)

# Example

console.log(isDate(new Date)) // true