通俗的讲,instanceof,是从原型链上寻找是否有此实例,
typeof,返回的是原型链最顶点的数据类型,
hasOwnProperty,则是用来判断自身是否真的有此属性或方法(自身原有的,非继承的)
<script>
class Person{
constructor(name){
this.name = name
}
say(){
console.log('???');
}
}
class Man extends Person{
constructor(name,age){
super(name)
this.age = age
}
speak(){
console.log('sss');
}
}
const man = new Man("Bob", 18)
console.log(typeof man); //object
console.log(man.hasOwnProperty('name')); //true
console.log(man.hasOwnProperty('speak')); //false speak是构造函数的方法
man.say()
man.speak()
console.log(man instanceof Person); //true
</script>