深度封装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))

猜你喜欢

转载自www.cnblogs.com/xm16/p/10357743.html
今日推荐