继承-原型链

mac2022-06-30  19

 1  function SuperType() {  2      this.property =  true;  3 }  4   5 SuperType.prototype.getSuperValue =  function() {  6      return  this.property;  7 };  8   9  function SubType() { 10      this.subproperty =  false; 11 } 12  13  // 继承了 SuperType 14 SubType.prototype =  new SuperType(); 15  16 SubType.prototype.getSuperValue =  function() { 17      return  this.subproperty; 18 }; 19  20  var instance =  new SubType(); 21 console.log(instance.getSuperValue()); 22  23 console.log(instance  instanceof Object); 24 console.log(instance  instanceof SuperType); 25 console.log(instance  instanceof SubType); 26  27 console.log(Object.prototype.isPrototypeOf(instance)); 28 console.log(SuperType.prototype.isPrototypeOf(instance)); 29 console.log(SubType.prototype.isPrototypeOf(instance));

转载于:https://www.cnblogs.com/qzsonline/archive/2012/04/26/2470893.html

最新回复(0)