Wednesday, December 14, 2022

Typescript inheritance example with code

 Typescript inheritance example with code

    Code example - https://typescript-bc7fcz.stackblitz.io


This video explains how to do inheritance in Typescript using examples. Code example - https://stackblitz.com/edit/typescript-bc7fcz?file=index.ts First we will create a parent class called Person. This class has two properties first name and last name. Write a constructor method to set these two properties. We will also have two methods. One for getting the full name and another describe method. Now the person class is ready. We are going to create an instance of this class using a new keyword. Using this instance we can call the two methods of Person class. Now we will see how to create a child class using Typescript inheritance. Typescript uses a keyword 'Extends' to inherit properties of another class. The constructor method of the child class should call super method , so that the parent constructor is invoked. Similar to parent class we can create an instance of child class . Since Student class is inherited from Person class, it can access its Parent class methods as well as its own methods. Why do we use inheritance? We can use it for Method Overriding (so runtime polymorphism can be achieved). We can use it for Code Reusability.

First we will create a parent class called Person. This class has two properties first name and last name. Write a constructor method to set these two properties. We will also have two methods. One for getting the full name and another describe method.

Now the person class is ready. We are going to create an instance of this class using a new keyword. Using this instance we can call the two methods of Person class.


Now we will see how to create a child class using Typescript inheritance. Typescript uses a keyword 'Extends' to inherit properties of another class. The constructor method of the child class should call super method , so that the parent constructor is invoked. Similar to parent class we can create an instance of child class . Since Student class is inherited from Person class, it can access its Parent class methods as well as its own methods.

Why do we use inheritance? We can use it for Method Overriding (so runtime polymorphism can be achieved). We can use it for Code Reusability.



Thursday, December 8, 2022

Formatting and styling console.log messages in web browser console

Formatting and styling console.log messages in web browser console

Sunday, November 27, 2022

How to install your own extension in Firefox browser

How to install your own extension in Firefox browser . Create your extension files or get a sample extension files from GITHUB. We are going to use Borderify extension. This extension add a red border around the mozilla website . Once extension files are ready open a new tab and type about : debugging. Click on the blue color This Firefox link button. This will take you to the Temporary extensions page. Click on Load temporary add on button. Browse and select any file from your extension folder. This will install the selected extension . To test the extension open the mozilla.org website in the new tab. You can see a red color border around the website . Download sample extensions from link https://github.com/mdn/webextensions-examples/

Friday, November 25, 2022

Visual Studio Code - HTML live preview extension

Visual Studio Code - HTML live preview extension

Sunday, November 20, 2022

Sunday, November 13, 2022

Best JavaScript editors 2023

Best JavaScript editors 2023

Thursday, November 10, 2022

Angular non singleton services

 Angular non singleton services