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));

相关文章:

  • 2021-06-03
  • 2022-12-23
  • 2021-09-13
  • 2021-11-06
  • 2021-10-18
  • 2021-10-11
  • 2021-06-19
  • 2021-10-01
猜你喜欢
  • 2021-08-05
  • 2021-11-07
  • 2021-07-21
  • 2021-07-11
  • 2021-05-01
相关资源
相似解决方案