只有函数才有prototype这个属性,对象只有proto属性
原型分为显示原型 (prototype)和隐式原型 (proto)
所有的引用类型都有proto属性,并指向其构造函数的prototype
引用类型:Array Object Function Date RegExp
a instanceOf b 用来判断 b的显示原型是否在a的原型链上
//手写instanceOf
function instance_Of(a,b){
//如果为基本数据类型,直接返回false
const baseType = ['string', 'number', 'boolean', 'undefined', 'symbol']
if(baseType.includes(typeof(a))) { return false }
let a = a.__proto__
let b = b.prototype
while(true){
if(a === null){
return false
}
if(a === b){
return true
}
//如果a.__proto__ !== b.prototype,就继续在a的原型链上往下访问
a = a.__proto__
}
}