JSFiddle - React, Tailwind, and code Playground
by javaparknet
JavaScript
function getType(x){
// x가 널이면 null을 리턴
if(x === null) return 'null';
var t = typeof x;
if( t!= 'object') return t;
var c = Object.prototype.toString.apply(x); // '[object class]' 리턴
c = c.substring(8, c.length-1); // class 만 남김
if( c!= 'Object') return c;
if(x.constructor == Object) return c;
if("classname" in x.constructor.prototype &&
typeof x.constructor.prototype.classname == "string")
return x.constructor.prototype.classname;
return "<unknown type>";
}
alert(getType(function test(){}));
alert(getType({}));
alert(getType([]));