首页 > 其他 > 详细

深度封装typeof判断

时间:2019-02-09 18:29:10      阅读:179      评论:0      收藏:0      [点我收藏+]
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))

 

深度封装typeof判断

原文:https://www.cnblogs.com/xm16/p/10357743.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!