11# 函数的类型
22
3- > [ 函数是 JavaScript 中的一等公民。 ] ( https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/ch2.html )
3+ > [ 函数是 JavaScript 中的一等公民] ( https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/ch2.html )
44
55## 函数声明(Function Declaration)
66
@@ -66,11 +66,11 @@ let mySum: (x: number, y: number) => number = function (x: number, y: number): n
6666
6767在 TypeScript 的类型定义中,` => ` 用来表示函数的定义,左边是输入类型,需要用括号括起来,右边是输出类型。
6868
69- > Tip: ` => ` 在 ES6 中叫箭头函数,应用十分广泛,可以参考 [ ES6 中的箭头函数] 。
69+ 其中, ` => ` 在 ES6 中叫箭头函数,应用十分广泛,可以参考 [ ES6 中的箭头函数] 。
7070
7171## 接口中函数的定义
7272
73- 在接口中,需要这样定义一个函数 :
73+ 我们也可以使用接口的方式来定义一个函数需要符合的形状 :
7474
7575``` ts
7676interface SearchFunc {
@@ -92,7 +92,7 @@ mySearch = function(source: string, subString: string) {
9292``` ts
9393function buildName(firstName : string , lastName ? : string ) {
9494 if (lastName ) {
95- return firstName + " " + lastName ;
95+ return firstName + ' ' + lastName ;
9696 } else {
9797 return firstName ;
9898 }
@@ -106,7 +106,7 @@ let xcat = buildName('Xcat');
106106``` ts
107107function buildName(firstName ? : string , lastName : string ) {
108108 if (firstName ) {
109- return firstName + " " + lastName ;
109+ return firstName + ' ' + lastName ;
110110 } else {
111111 return lastName ;
112112 }
@@ -123,7 +123,7 @@ let xcat = buildName(undefined, 'Xcat');
123123
124124``` ts
125125function buildName(firstName : string , lastName : string = ' Liu' ) {
126- return firstName + " " + lastName ;
126+ return firstName + ' ' + lastName ;
127127}
128128let xcatliu = buildName (' Xcat' , ' Liu' );
129129let xcat = buildName (' Xcat' );
@@ -133,7 +133,7 @@ let xcat = buildName('Xcat');
133133
134134``` ts
135135function buildName(firstName : string = ' Xcat' , lastName : string ) {
136- return firstName + " " + lastName ;
136+ return firstName + ' ' + lastName ;
137137}
138138let xcatliu = buildName (' Xcat' , ' Liu' );
139139let xcat = buildName (undefined , ' Xcat' );
@@ -169,14 +169,12 @@ let a = [];
169169push (a , 1 , 2 , 3 );
170170```
171171
172- > Tip: 注意 rest 参数只能是最后一个参数,关于 rest 参数,可以参考 [ ES6 中的 rest 参数] 。
172+ 注意, rest 参数只能是最后一个参数,关于 rest 参数,可以参考 [ ES6 中的 rest 参数] 。
173173
174- ## Links
174+ ## 参考
175175
176- - [ Handbook - Functions] ( http://www.typescriptlang.org/docs/handbook/functions.html )
177- - [ Handbook - Functions # Function Types] ( http://www.typescriptlang.org/docs/handbook/interfaces.html#function-types )
178- - [ 中文手册 - 函数] ( https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Functions.html )
179- - [ 中文手册 - 接口 # 函数类型] ( https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Interfaces.html#函数类型 )
176+ - [ Handbook - Functions] ( http://www.typescriptlang.org/docs/handbook/functions.html ) | [ 中文版] ( https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Functions.html )
177+ - [ Handbook - Functions # Function Types] ( http://www.typescriptlang.org/docs/handbook/interfaces.html#function-types ) | [ 中文版] ( https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Interfaces.html#函数类型 )
180178- [ JS 函数式编程指南] ( https://llh911001.gitbooks.io/mostly-adequate-guide-chinese/content/ )
181179- [ ES6 中的箭头函数]
182180- [ ES6 中函数参数的默认值]
0 commit comments