原型链

由于__proto__是任何对象都有的属性,而js里面万物皆对象,所以会形成一条__proto__连起来的链条,递归访问__proto__必须最终到头,并且值为null

js引擎查找对象的属性时,先找到对象本身是否含有该属性,如果不存在,会在原型链上查找,但是不会查找自身的prototype

prototype是函数才有的属性

image.png
function Car() {}
Car.prototype.title = "DB"
let car = new Car()
console.log(car.prototype) // undefined
console.log(car.__proto__ === Car.prototype) //true
console.log(car.constructor) // function Car() {}
console.log(Car === Car.prototype.constructor) //true
console.log(car.constructor === Car.prototype.constructor) //true

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容