原型继承
1 /** 2 父亲 3 */ 4 function Father(){ 5 this.password='123456'; 6 this.sex='男'; 7 } 8 9 Father.prototype = { 10 name : 'pine', 11 age : 27, 12 getName:function(){ 13 console.info('==>getName'); 14 return Father.prototype.name; 15 } 16 }; 17 Father.prototype.constructor=Father; 18 19 /** 20 孩子 21 */ 22 function Son(){ 23 } 24 25 Son.prototype=Object.create(Father.prototype); 26 Son.prototype.address = '杭州市西湖区'; 27 Son.prototype.birth = '1991-05-07'; 28 Son.prototype.constructor=Son; 29 30 var son = new Son(); 31 son 32 son instanceof Father 33 son instanceof Son 34 35 son.name 36 son.age 37 son.getName() 38 son.address 39 son.birth 40 son.password 41 son.sex 42 43 Father.prototype.constructor==Father 44 Son.prototype.constructor==Son 45 46 47 /** 48 原型继承 49 只能继承父类原型中的属性,不能继承父类this中的属性 50 子类实例对象既是 父类 的实例,又是 子类 的实例 51 52 53 54 55 */