JavaScript Return Object.Type

var getType = function(obj) {
    if (obj == null) {
        return String(obj);
    }
    return typeof obj === 'object' || typeof obj === 'function' ? obj.constructor && obj.constructor.name && obj.constructor.name.toLowerCase() || /function\s(.+?)\(/.exec(obj.constructor)[1].toLowerCase() : typeof obj;
};

 

posted @ 2016-09-05 09:18  shidengyun  阅读(359)  评论(0编辑  收藏  举报