JavaScript Class Inheritance 🚀
👇🧵
👇🧵
Don't forget to bookmarked it for future reference...
• In the above example, the Student class inherits all the methods and properties of the Person class.
Hence, the Student class will now have the name property and the greet() method.
Then, we accessed the greet() method of Student class by creating a student1 object.
Hence, the Student class will now have the name property and the greet() method.
Then, we accessed the greet() method of Student class by creating a student1 object.
• In the above example, super inside Student class refers to the Person class.
Hence, when the constructor of Student class is called, it also calls the constructor of the Person class which assigns a name property to it.
Hence, when the constructor of Student class is called, it also calls the constructor of the Person class which assigns a name property to it.
• In the above example, the occupation property and the greet() method are present in parent Person class and the child Student class.
Hence, the Student class overrides the occupation property and the greet() method.
Hence, the Student class overrides the occupation property and the greet() method.
Uses of Inheritance
• Once a functionality is developed, you can simply inherit it. No need to reinvent the wheel. This allows for cleaner code and easier to maintain.
• Since you can also add your own functionalities in the child class.
• Once a functionality is developed, you can simply inherit it. No need to reinvent the wheel. This allows for cleaner code and easier to maintain.
• Since you can also add your own functionalities in the child class.
End thread 🧵
If you liked this thread:
-RT the first thread and share it with folks on Twitter.
-Follow @personalvipin for more such insightful threads.
Thanks for reading!
If you liked this thread:
-RT the first thread and share it with folks on Twitter.
-Follow @personalvipin for more such insightful threads.
Thanks for reading!
جاري تحميل الاقتراحات...