Type Script基礎学習ノート(二)
2134 ワード
Typeescriptの関数関数の定義 方法オプションパラメータ デフォルトパラメータ 残パラメータ 関数再負荷 矢印関数s 6
//js
function fun () {
return 'string';
}
//typescripe
function fun () : string {
return 'string';// function
}
//
let fun2 = function () :number{
return 123;
}
//
function fun3 (name:string,age:number) :string{
return `${name} --- ${age} `;
}
alert(fun3('wen',23));
//
function run () : void{
console.log('run');
}
run()
function getInfo(name:string,age?:number) : string {// ?
if(age){
return `${name} --- ${age}`
}else{
return `${name}` };
}
function getInfo(name:string,age:number = 20) : string { age , ,
if(age){
return `${name} --- ${age}`
}else{
return `${name}` };
}
function sum (a:number,b:number,c:number):number {
return a+b+c ;
}
//
function sum (...resuylt:number[]):number {
let sum = a;
for(let i=0;i
//java : , , ;
//ts : ;
//es5 ,
function css (config:any):any {
}
function css (config:any,value:any):any {
}
//ts
function getInfo (name:string) : string;
function getInfo (age:number) : number;
function gerInfo (str:ant) : any {
if( typeof str === 'string' ) {
return 'I'm:‘ + str ;
} else {
return 'age:’ + str ;
}
}
alert ( getInfo('wen‘));--- :I'm:wen;
alert ( getInfo('20')); --- : age:20;
function getInfo (name:string) : string;
function getInfo (name:string,age:number) : number;
function gerInfo (str:ant) : any {
if( typeof str === 'string' ) {
return ' ’ +name+ 'age'+age ;
} else {
return ' :’ + name ;
}
}
alert (getInfo('wen')) ;//
//alert(getInfo(20));//
//this : this
setTime(()=>{
alert('run');
},1000)