js原型prototype(实例构造函数的属性) __proto__(实例对象的属性) constructor(实例构造函数prototyper的属性)

发布时间 2023-05-27 11:04:32作者: howhy
 function Person(name,age){
    this.name=name
    this.age=age
   }
   Person.prototype.sayHi=function(){//原型是公共方法
    console.log(this.name+' say hi!!')
   }
   const p1=new Person('aa',12)
   const p2=new Person('bb',14)
   p1.sayHi()
   p2.sayHi()
   console.log(p1.__proto__===Person.prototype) //true
   console.log(p2.__proto__===Person.prototype)//true
   console.log(p1.__proto__===p2.__proto__)//true
   console.log(Person.prototype.constructor===Person)//true