-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisObject.js
43 lines (40 loc) · 1.15 KB
/
isObject.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import isFunction from './isFunction'
import TYPES from './enum/types'
/**
* 检测测试数据是否为对象
* ========================================================================
* @method isObject
* @since 0.2.0
* @category Object
* @param {*} val - 要检测的数据
* @returns {Boolean} 'val' 为对象,返回 true,否则返回 false
* @example
*
* const $list = document.getElementById('list')
*
* // True
* isObject({}) // => true
* isObject(Object) // => true
* isObject(new Object()) // => true
* isObject(Object.create(null)) // => true
* isObject([]) // => true
* isObject(() => {}) // => true
* isObject(class {}) // => true
* isObject($list) // => true
*
* // False
* isObject('null') // => false
* isObject(1) // => false
* isObject(false) // => false
* isObject(Symbol('ok')) // => false
* isObject($list) // => false
*
* // 针对 null,type.js 认为不是一个有效对象
* // 以避免将 null 作为普通对象操作导致的错误
* isObject(null) // => false
*/
const isObject = (val) => {
const type = typeof val
return !!(val && (type === TYPES.OBJECT || isFunction(val)))
}
export default isObject