-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypescript.ts
More file actions
119 lines (74 loc) · 2.27 KB
/
Typescript.ts
File metadata and controls
119 lines (74 loc) · 2.27 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// var age:number=23;
// var marrige:boolean=true;
// console.log(age,marrige);
// var numbers:number[]=[1,2,3,4,5]
// console.log(numbers);
// enum man {sex,age=3,like};
// var lee_age=man.age;
// console.log(lee_age);
//
// class Report{
// data:string[];
// constructor(data:string[]){
// this.data=data;
// }
// run():void{
// this.data.forEach(function(d){
// console.log(d)
// })
// }
// }
//===========================================
// class TabReport extends Report{
// headers:string[];
// constructor(headers:string[],values:string[]){
// super(values);
// this.headers=headers;
// }
// run():void{
// console.log(this.headers);
// super.run();
// }
// }
// var tab=new TabReport(['Headers'],['extends']);
// tab.run();
//==============================
// var data:string[]=['one','two','three'];
// data.forEach(function(datas){
// console.log(datas);
// })
// data.forEach((m)=>console.log(m)); //快速书写函数,一个参数时,m的括号可省略
// var numbers:number[]=[1,2,3,4,5];
// numbers.map((m)=>{
// m=m+1;console.log(m)
// }); //Map方法,返回经过操作后的数组
//而且=>语法和外部代码拥有同样的this;
// var man={
// name:"lee",
// age:20,
// like:'guitar',
// guitars:['taylor','martin'],
// get:function(){
// this.guitars.forEach(function(g){
// var self=this;
// console.log(g);
// console.log(self.age)
// }) //this 即不是指代man,显示undefined,this是function()自己
// },
// get_name:function(){
// this.guitars.forEach((g)=>{
// console.log(g)
// console.log(this.name)
// console.log(this);
// }
// ) //this指向函数的调用者, 即指代man
// }
// }
// man.get();
// man.get_name();
//箭头函数是处理内联函数的好办法。这也让我们在JavaScript中更容易使用高阶函数。
//=============================
//模板字符串,类似于jsp中的
// var Name:string='lee';
// console.log(`hello ${Name}`)
//使用 `` 而不是 '',可多行插入