function Person(){this.name = 'xiaoming';this.showName = function(){return '我叫:' + this.name;};}var p1 = new Person();var p2 = new Person();console.log( p1.showName == p2.showName ); //false //原型:在构造函数下边的 -> prototype。原型也是一个对象,一般叫做原型对象。//通过原型操作的好处:就是可以让属性或方法成为多个对象的共享属性或方法,在内存中只存在一份,这样就可以节约内存。function Person(){this.name = 'xiaoming';}//console.log( typeof Person.prototype ); // 'object'//Person.prototype.name = 'xiaoming';Person.prototype.showName = function(){return '我叫:' + this.name;};var p1 = new Person();var p2 = new Person();console.log( p1.showName == p2.showName ); // true //-----------------------原型链//连接对象与原型对象之间的纽带就是原型链。(也就是 __proto__)function Person(){}Person.prototype.name = 'xiaoming'; // 原型对象var p1 = new Person(); // 创建的对象console.log( p1.__proto__ === Person.prototype ); // trueconsole.log( Person.prototype.__proto__ === Object.prototype ); //trueconsole.log( Object.prototype.__proto__ ); // null 最外层的原型链// 原型链的查找方式:就是从内层一层层向外查找。function Person(){this.age = 20;}Person.prototype.age = 30;Object.prototype.age = 40;var p1 = new Person();console.log( p1.age );