prototype in TypeScript

  • It is a static property of the number object.
  • It is used to assign a new properties and methods to an object in the current code.

Below is an example:

    function contact(name:string, phone:number){
        this.name=name;
        this.phone=phone;
    }
    var user1=new contact("Akanksha",9876543210);
    contact.prototype.address="Delhi";
    console.log("Name: " + user1.name);
    console.log("Phone: " + user1.phone);
    console.log("Address: " + user1.address);

Below is the output of above code:

Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started