<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>
posted on 2018-04-12 14:52  仔仔爱学习  阅读(283)  评论(0编辑  收藏  举报