首页 > Web开发 > 详细

jQuery--- .hasOwnProperty 用法

时间:2018-05-15 21:43:57      阅读:1335      评论:0      收藏:0      [点我收藏+]
☆  obj.hasOwnProperty(‘prop‘):  是用来判断一个对象是否有你给出名称的属性或对象。不过需要注意的是,
    此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员。
    <script type="text/javascript">
        var obj = {
            a: 1,
            fn: function(){ },
            c:{
                d: 5
            }
        };
        console.log(obj.hasOwnProperty(‘a‘  ));  //true
        console.log(obj.hasOwnProperty(‘fn‘ ));  //true
        console.log(obj.hasOwnProperty(‘c‘  ));  //true
        console.log(obj.c.hasOwnProperty(‘d‘));  //true
        console.log(obj.hasOwnProperty(‘d‘  ));  //false, obj对象没有d属性
        var str = new String();
        console.log(str.hasOwnProperty(‘substring‘));//false
        console.log(String.prototype.hasOwnProperty(‘substring‘));//true
    </script>

 

jQuery--- .hasOwnProperty 用法

原文:https://www.cnblogs.com/hahajava/p/9042876.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!