File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change 11// Determine the type of a variable/object.
22export const objType = function ( obj ) {
3- if ( typeof obj === 'undefined' ) return 'undefined' ;
4- else if ( typeof obj === 'string' || obj instanceof String ) return 'string' ;
5- else if ( typeof obj === 'number' || obj instanceof Number ) return 'number' ;
6- else if ( ! ! obj && obj . constructor === Array ) return 'array' ;
7- else if ( obj && obj . nodeType === 1 ) return 'element' ;
8- else if ( typeof obj === 'object' ) return 'object' ;
9- else return 'unknown' ;
3+ var type = typeof obj ;
4+ if ( type === 'undefined' ) return 'undefined' ;
5+ else if ( type === 'string' || obj instanceof String ) return 'string' ;
6+ else if ( type === 'number' || obj instanceof Number ) return 'number' ;
7+ else if ( type === 'function' || obj instanceof Function ) return 'function' ;
8+ else if ( ! ! obj && obj . constructor === Array ) return 'array' ;
9+ else if ( obj && obj . nodeType === 1 ) return 'element' ;
10+ else if ( type === 'object' ) return 'object' ;
11+ else return 'unknown' ;
1012} ;
1113
1214// Create an HTML element with optional className, innerHTML, and style.
You can’t perform that action at this time.
0 commit comments