How to implement guide with inheritance and method overriding in es6 classes
I'm optimizing some code but I'm relatively new to this, so bear with me. I'm working on a project and hit a roadblock. Quick question that's been bugging me - I'm stuck on something that should probably be simple... I'm running into a question with method overriding in my ES6 class hierarchy. I have a base class called `Animal` with a method `speak()` that prints a message. My derived class `Dog` is supposed to override this method, but when I call `speak()` on an instance of `Dog`, it seems to invoke the base class method instead of the overridden one. Hereβs a simplified version of my code: ```javascript class Animal { speak() { console.log('Animal speaks'); } } class Dog extends Animal { speak() { console.log('Dog barks'); } } const dog = new Dog(); dog.speak(); // Expected: 'Dog barks' ``` However, when I run this code, I'm getting the output 'Animal speaks' instead of 'Dog barks'. I suspect this might be related to how I'm instantiating the class or some scenario with the prototype chain, but I need to pinpoint it. I've also tried making sure that there are no typos in the method names and that the inheritance is set up correctly. I verified that my JavaScript environment fully supports ES6 classes. I'm using Node.js version 14, which should support these features without issues. Any insights into what might be causing this unexpected behavior would be greatly appreciated! This is part of a larger CLI tool I'm building. How would you solve this? For context: I'm using Javascript on Linux. I'd really appreciate any guidance on this. Any help would be greatly appreciated! This is my first time working with Javascript 3.10. The stack includes Javascript and several other technologies. Thanks for your help in advance!