<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<script type="text/javascript">
/*
1.什么是instanceof关键字?
instanceof用于判断 "对象" 是否是指定构造函数的 "实例"
*/
/*
2.instanceof注意点
只要 构造函数的原型对象出现在实例对象的原型链中都会返回true
意思是person的构造函数所指向的person原型对象出现在了student的原型链中就行了
*/
/*class Person
{
name="cyg";
}
let qq=new Person();
console.log(qq instanceof Person);//qq实例是不是person构造函数所创建的实例对象
class Cat{
name = "mm";
}
let c = new Cat();
console.log(c instanceof Person);*/
function Person(myName) {
this.name = myName;
}
function Student(myName, myScore) {
Person.call(this, myName);
this.score = myScore;
}
Student.prototype = new Person();
Student.prototype.constructor = Student;
let stu = new Student();
console.log(stu instanceof Person); // true
</script>
</body>
</html>