JavaScript 返回具体类型方法

/**
 * 返回target类型
 * @param {} target 
 */
function type(target) {
    var ret = typeof (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 (ret == "object") {
        var str = Object.prototype.toString.call(target);
        return template[str];
    } else {
        return ret;
    }
}

 

posted @ 2019-04-17 06:50  110来了  阅读(775)  评论(0编辑  收藏  举报