js之function与object的原型链关系

js之function与object的原型链关系

自己第一次用xmind画的图,比较丑。
Function与Object的原型关系图
看红宝书的时候看到创建对象的几种方式时,突然想到这个,顺手划一波。

 //构造函数模式
 function Person(name,age){
        this.name=name;
        this.age=age;
        this.getName=function(){
            return this.name
        }
    }
     let p1=new Person('zhangsan',12);
     let p2=new Person('wangwu',23);
     console.log(p1.__proto__==Person.prototype); //true
     console.log(Person.__proto__==Function.prototype); //true
     console.log(Function.prototype.__proto__==Object.prototype);//true
     console.log(Function.__proto__==Object.prototype);//false
     console.log(p1 instanceof(Person));  //true
     console.log(p1 instanceof(Function));//false
     console.log(p1 instanceof(Object));//true
     console.log(Function.prototype.__proto__==Object.prototype)  //true
     console.log(Object.__proto__==Function.prototype)  //true

猜你喜欢

转载自blog.csdn.net/weixin_42123213/article/details/112692120