function Person(name,age){ this.name=name this.age=age } Person.prototype.sayHi=function(){//原型是公共方法解决构造函数new对象公共属性和方法的内存浪费 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
标签:__,console,proto,Person,实例,prototype,构造函数 From: https://www.cnblogs.com/howhy/p/17436410.html