1. hasOwnProperty()可以判断属性时私有的还是共有的
2.在构造函数中
(1)共有:一般在原型对象上
(2)私有属性,通过this关键字去添加的
<script>function Person(name,age){this.name=name;this.age=age;}/*在构造函数中共有:一般在原型对象上私有属性,通过this关键字去添加的hasOwnProperty()可以判断属性时私有的还是共有的*/Person.prototype= {constructor:Person,sayName(){console.log(this.name);},sayAge(){console.log(this.age);}}var p=new Person("zhang",20);console.log(p.hasOwnProperty("name")); //trueconsole.log(p.hasOwnProperty("sayName")); //false</script>
