image.png
image.png
image.png
image.png
image.png
沿着A的__proto__这条线来找,同时沿着B的prototype这条线来找,如果两条线能找到同一个引用,
即同一个对象,那么就返回true。如果找到终点还未重合,则返回false。
image.png
eg:
function fn(){
console.log("123")
}
function Person(name,age){
this.name =name;
this.age=age;
this.say = function(){
console.log("我是"+this.name)
}
}
var one = new Person("张三",26);
var zhangsan = {"name":"张三","height":185};
//每个函数都有一个prototype属性,prototype属性是一个对象,(属性的集合)
console.log(fn.prototype.constructor===fn);//true fn.prototype属性是fn的原型属性的集合。包括constructor的属性
console.log(Person.prototype.constructor ===Person);//true
console.log(Person.__proto__ ===Function.prototype);//true Person是一个函数,同样也是一个对象,它是由Function创建,
console.log(fn.__proto__===Function.prototype);// true fn有Function创建 new Function();
console.log(Object.__proto__===Function.prototype);// true Object也是有Function创建
console.log(one.__proto__===Person.prototype);//true 对象one是由函数Person创建
console.log(zhangsan.__proto__===Object.prototype);//true 对象"zhangsan"是由Object创建
//结论:每一个对象都有一个__proto__属性,指向构建这个对象的函数的prototype,
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有