如何判断一个对象实例是不是某个类型,如Cat类型

<script>
    function cat(){}
    var b = new cat();

    if(b instanceof cat){
        console.log("a是cat")
    }
    if(b.constructor==cat){
        console.log("a是cat")
    }
    //两种方法都可以
</script>

猜你喜欢

转载自www.cnblogs.com/alex-xxc/p/9984736.html