79156098

Date: 2024-11-04 15:45:38
Score: 1
Natty:
Report link

In the original code, the issue was that calling this.foobar() in A's constructor invoked the foobar method of the derived class (B), if B overrode it. This happened because this in the A constructor refers to the instance being created, which is actually an instance of B.

To resolve this, you directly call A.prototype.foobar.call(this); within A's constructor instead of this.foobar(). This approach ensures that A's original foobar method is called, even if B or any other subclass overrides foobar.

So, instead of relying on this to find the method, we specifically tell JavaScript to use A's version of foobar.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Vijay Jadeja