(书名:JavaScript从入门到精通)
function如有欠缺可评论或私信我,希望和大家一起学习
1.自定义获取数据类型
function typeOf(o){
let _toString=Object.prototype.toString;
let _type={
"undefined":"undefined",
"number":"number",
"string":"string",
"boolean":"boolean",
"[object Function]":"function",
"[object RegExp]":"regexp",
"[object Math]":"math",
"[object Array]":"array",
"[object Date]":"date",
"[object Error]":"error"
}
return _type[typeof o] || _type[_toString.call(o)] || (o instanceof Object?o.constructor.name:'object') || (o ? "object" : "null"); }