Can't call static method in JavaScript parent class -


i'm trying access static method basearea parent class cars shows following error:

test.php:34 uncaught typeerror: (intermediate value).basearea not function     @ bike.get bikearea [as bikearea] (test.php:34)     @ test.php:42 

but works fine when use basearea () {} instead of static basearea() {}

what doing wrong?

class cars {     constructor(x, y) {         this.height = x;         this.width = y;     }      static basearea() {         return 44;     } }  class bike extends cars {     constructor(flag) {         super(flag, flag);     }      bikearea() {         return super.basearea();     } }  let bike = new bike(10); console.log(bike.bikearea); 

it not work because super. referencing class instance. , static method not attached instances class themselves.

however, following work:

class cars {     constructor(x, y) {         this.height = x;         this.width = y;     }      static basearea() {         return 44;     } }  class bike extends cars {     constructor(flag) {         super(flag, flag);     }      bikearea() {         return bike.basearea();     } } 

note bike.basearea().

in example linked here, likel works because pingpong method static , called computer.pingpong() , not new computer().pingpong() whole chain static. maybe in circumstances succeed resolve super.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -