深度封装typeof判断

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))

 

posted @ 2019-02-09 17:54  阿|明  阅读(269)  评论(0编辑  收藏  举报