function myTypeof(val){ var type = typeof(val); var myString = Object.prototype.toString; var res = { ‘[object Object]‘ : ‘object‘, ‘[object Array]‘ : ‘array‘, ‘[object Number]‘ : ‘object number‘, ‘[object String]‘ : ‘object string‘, ‘[object Boolean]‘ : ‘object boolean‘, }; if(val === null){ return ‘null‘ }else if(type == ‘object‘){ var tt = myString.call(val); return res[tt] }else{ return type } } console.log(myTypeof(new Number))
原文地址:https://www.cnblogs.com/xm16/p/10357743.html
时间: 2024-10-09 11:56:33