-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathts5.ts
More file actions
56 lines (45 loc) · 1.46 KB
/
ts5.ts
File metadata and controls
56 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Class
//public : یک پراپرتی معمولی
//private : فقط داخل کلاس قابل دسترسی میباشد
//readonly : غیر قابل تغیر
//? : پراپرتی اختیاری
//static : دسترسی به متد و پراپرتی مستقیم از طریق کلاس و لازم به نمونه نباشد
class Users{
constructor(public id:number, private readonly _name:string,private pass:number, public loc?:string){} //propertes
name(){
console.log(this.id + this._name);
}
private ShowPass(){
console.log(this.pass);
}
FullName(){
this.ShowPass()
}
static ShowLoc(){
console.log('OK');
}
//برای گرفتن پراپرتی های پرایوت از گتر استفاده میکنیم
get GetPass():number{ return this.pass}
// برای ست کردن مقداری به پراپرتی های پرایوت از ستر استفاده میکنیم
set SetPass(passwor:number){
if(passwor >= 1000){
this.pass = passwor
}else{
console.log('No!!!');
}
}
}
let mohammad = new Users(1,'mohaamad',1234)
//ارث بری
class nums{
constructor(public num_1:number, public num_2:number) {}
}
class numbers extends nums{
constructor(public num_1,public num_2,public num_3) {
super(num_1,num_2);
}
plus(){
console.log(this.num_1 + this.num_2 + this.num_3)
}
}
let P = new numbers(1,5,98)