构造函数-原型对象和实例对象关系

75 阅读1分钟
/* 
    构造函数 
*/ 
function Person() { 
    this.name = 'jack'
    this.age = 20 
    this.say = function () {
        console.log(this.name, '说话'); 
    }
} 

let p1 = new Person() //实例对象

console.dir(Person) //打印构造函数 
console.dir(Person.prototype) //原型对象
console.dir(p1) 

console.log( p1.__proto__ == Person.prototype);

QQ图片20220223201856.png