JS的数据类型和类型获取判断(含自定义方法)

判断变量类型的自定义方法

function ccTypeof(cc) {
        var typename = Object.prototype.toString.call(cc);
        if(typename == '[Object,Object]'){
            typename = '[object' + cc.constructor.name + ']';
        }
        return typename;
        /*if(cc === null){return 'null';};
        return typeof(cc);*/
        //return cc === null? 'null' : typeof(cc);
    }
无标题12.png
微信图片_20181217204501.png

typeof调试

微信图片_20181217181820.png

你可能感兴趣的:(JS的数据类型和类型获取判断(含自定义方法))