/*
1.什么是isPrototypeOf属性
isPrototypeOf用于判断 一个对象是否是另一个对象的原型
*/
/*
2.isPrototypeOf注意点
2.1只要调用者在传入对象的原型链上都会返回true
*/
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
/*
1.什么是isPrototypeOf属性
isPrototypeOf用于判断 一个对象是否是另一个对象的原型
*/
/*
2.isPrototypeOf注意点
2.1只要调用者在传入对象的原型链上都会返回true
*/
/*class Person
{
name="cyg";
}
let p=new Person();
console.log(Person.prototype.isPrototypeOf(p));
//判断p对象的原型链中是否存在person。就会返回true。否则false。
class Cat{
name = "mm";
}
console.log(Cat.prototype.isPrototypeOf(p));
*/
function Person(myName) {
this.name = myName;
}
function Student(myName, myScore) {
Person.call(this, myName);//第一步通过call把person类改成student。
this.score = myScore;
}
//第二步再修改student的原型对象为new Person();
Student.prototype = new Person();
//并把Student.prototype.constructor指向了student的构造函数。
Student.prototype.constructor = Student;
let stu = new Student();
console.log(Person.prototype.isPrototypeOf(stu)); // true
</script>
</body>
</html>