类本身指向就是构造函数,类的数据类型就是函数;
function Person(name){
this.name=name;
}
const obj=new Person("张三");
方法1: instanceof
判断构造函数的prototype属性是否出现在对象的原型链的任何位置
const obj = new Person("张三");
const obj2={}
console.log(obj instanceof Person);//true
console.log(obj2 instanceof Person);//false
方法2: constructor
对象的属性 constructor来判断,指向该对象的构造函数
const obj = new Person("张三");
console.log(obj.__proto__.constructor);//[Function: Person]
这种方式不是很好,因为constructor属性是可以修改的.
const obj = new Person("张三");
obj.__proto__.constructor=Array;
console.log(obj.__proto__.constructor);//[Function: Array]