SOURCE

var class2type = {};
var type_String = class2type.toString; //=> Object.prototype.toString
['String','Boolean','Number','Array','Function','Object','Error','RegExp','Date'].forEach(name=>{
    class2type[`[object ${name}]`] = name.toLowerCase();
});
console.log(class2type)
var toType = function(obj){
    // console.log(type_String.call(obj))
    if(obj == null) return String(obj);
    return typeof obj == 'object' || typeof obj == 'function' ? 
        class2type[type_String.call(obj)] || 'object' : typeof obj
}

Object.toType = toType;

console.log(toType('aaa'))
console.log(toType(12))
console.log(toType(true))
console.log(toType(['1','2']))
console.log(toType({}))
console.log(toType(new Date()))
console 命令行工具 X clear

                    
>
console