Javascript Coding Challenges for Beginners Q5

Transcript

English (Auto-generated)

Hello everyone. Welcome to my javascript coding challenge course for beginners. Again. For today's challenge, we will work on more javascript classes and constructors, but this time we'll be extending to a subclass and we can do that by using the super and extend keyword. So we'll be using the same example from before. If you have completed question for you will see that this pet class comes exactly or directly from him. But for this question we want to create a class name. Dog, which will inherit the methods from the pet class and we can do that by using the extended keyword. So go ahead and pause the video and come up with their own solution. When you're ready. We can work on the solution together. Now that you're ready, let's write our dog class a lot of times we have something called Pet glass and it's very general and sometimes maybe we want to be more specific because dogs have four legs and um some animals have two legs. I can't think of one on top of the mine. So sometimes we need a specific subclass for them. But for this tutorial we'll just go swiftly introduce how do we write this right class. Dog extends pet. So this is how you exactly right it to get a subclass. So now dog is a subclass of pet. You can think of it this way and remember that each class has a constructor. So let's write our constructor. The constructor still takes in the first name and last name because dog is a subclass of pet, which means the dogs still have the property, first name and last name. So let's write that down. And in order to make this a bit more different, let's add something else to make this subclass special. So maybe dog has a toy, so it will take in a parameter called toy. And then now inside constructor, we have to write something called Super. What Super does is it's gonna call.
110 Views 0 Likes 0 Comments

Extension of classes and constructors!

Comment
Leave a comment (supports markdown format)