<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<script>
function Person() {
}
Person.prototype.name="Nicholas";
Person.prototype.age=29;
Person.prototype.sayName=function(){
alert(this.name);
}
var person1=new Person();
person1.name="Greg";
var person2=new Person();
console.log(person1.hasOwnProperty("name"));
console.log(person2.hasOwnProperty("name"));
console.log("name" in person1);
console.log("name" in person2);
for (var prop in person1) {
console.log(prop);
}
function hasPrototypeProperty(object,pro) {
return (!object.hasOwnProperty(pro))&&(pro in object);
}
console.log(hasPrototypeProperty(person1,"name"));
console.log(hasPrototypeProperty(person2,"name"));
</script>
<body>
</body>
</html>