The Prototype Property in TypeScript which is used to add properties and methods to an object.Â
Syntax:
string.prototype
Return Value: This method does not returns any value.Â
Below examples illustrate the String Prototype property in TypeScript
Example 1:Â
function Person(name:string, job:string, yearOfBirth:number)
{
this.name= name;
this.job= job;
this.yearOfBirth= yearOfBirth;
}
// Driver code
var emp = new Person("Smith", "ABC",12214)
// This will show Person's prototype property.
console.log(emp.prototype);
Output:Â
Example #2:Â
Â
function Person(name:string, job:string, yearOfBirth:number)
{
this.name= name;
this.job= job;
this.yearOfBirth= yearOfBirth;
}
// Driver code
var emp = new Person("Smith", "ABC",12214)
// This will show Person's prototype property.
Person.prototype.email = "abc@123.com";
console.log("Person's name: " + emp.name);
console.log("Person's Email ID: " + emp.email);
Output:Â