构造函数、原型对象、实例对象三者关系

261 阅读1分钟

构造函数、原型对象、实例对象三者关系

image.png

 <script>
        /*
          构造函数
        */
        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);
    </script>

image.png