您好,欢迎来到知库网。
搜索
您的当前位置:首页hasOwnProperty方法与isPrototypeOf方法

hasOwnProperty方法与isPrototypeOf方法

来源:知库网

hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象。不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
isPrototypeOf:是用来判断要检查其原型链的对象是否存在于指定对象实例中,是则返回true,否则返回false。

function SetObj(name,age){
        this.name=name;
        this.age=age;
    }
    SetObj.prototype.sayName=function (){
        console.log("xxx")
    }
    var b1=new SetObj("xiaohua",45);
    console.log(b1.hasOwnProperty("name")); //true
    console.log(b1.hasOwnProperty("sayName")); //false
    console.log(SetObj.prototype.hasOwnProperty("sayName")); //true
    console.log(SetObj.prototype.isPrototypeOf(b1));//true

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务