📜  打字稿 |字符串原型属性

📅  最后修改于: 2022-05-13 01:56:37.389000             🧑  作者: Mango

打字稿 |字符串原型属性

TypeScript中的Prototype Property()用于向对象添加属性和方法。
句法:

string.prototype 

返回值:此方法不返回任何值。
下面的示例说明了 TypeScript 中的String Prototype 属性
示例 1:

JavaScript
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);


JavaScript
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);


输出:

示例 #2:

JavaScript

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);

输出: