خاصیت Prototype شیء String در TypeScript
خاصیت Prototype شیء String در زبان برنامه نویسی تایپ اسکریپت به شما امکان اضافه کردن متدها و خاصیت های جدید به یک شیء را می دهد.
مثال:
1 2 3 4 5 6 7 8 9 | function employee(id:number,name:string) { this.id = id this.name = name } var emp = new employee(123,"Smith") employee.prototype.email="smith@abc.com" console.log("Employee 's Id: "+emp.id) console.log("Employee's name: "+emp.name) console.log("Employee's Email ID: "+emp.email) |
کد فوق بعد از کامپایل:
1 2 3 4 5 6 7 8 9 10 | //Generated by typescript 1.8.10 function employee(id, name) { this.id = id; this.name = name; } var emp = new employee(123, "Smith"); employee.prototype.email = "smith@abc.com"; console.log("Employee 's Id: " + emp.id); console.log("Employee's name: " + emp.name); console.log("Employee's Email ID: " + emp.email); |
خروجی:
1 2 3 | Employee’s Id: 123 Emaployee’s name: Smith Employee’s Email ID: smith@abc.com |
هیچ نظری ثبت نشده است