JS —— 判断类型

function type (target){
            var template = {
                '[object Array]' : 'array',
                '[object Object]' : 'object',
                '[object Number]' : 'number-object',
                '[object Boolean]' : 'boolean-object',
                '[object String]' : 'string-object',
            }
            if(target === null){
                return "null";
            }else if(typeof(target) == 'object'){
                var set = Object.prototype.toString.call(target);
                return template[set];
            }else{
                return typeof(target);
            }
        }
posted @ 2019-09-20 09:35  杨培贤  阅读(230)  评论(0编辑  收藏  举报