hasOwnProperty可以判断实例属性是否私有<br /> 公有属性一般在原型对象上<br /> 私有属性 通过this关键字去添加的
<script> function Person(name,age){ this.name = name; this.age = age; } Person.prototype ={ sayName:function(){ console.log(this.name) }, sayAge(){ console.log(this.age) } } var a = new Person("cheng",20); // hasOwnProperty可以判断实例属性是否私有 // 公有属性一般在原型对象上 // 私有属性 通过this关键字去添加的 // console.log(a.hasOwnProperty("name")) //true console.log(a.hasOwnProperty("sayName")) //false console.log(a.hasOwnProperty("constructor")) //false var obj = { name:"zhang" } console.log(obj.hasOwnProperty("name")) //true </script>