标签:ber any 变量 script 返回 ons i++ cond ret
声明标识 + 变量名 + 声明类型 = 值
var a:number = 56; (C => int a = 5;)
enum REN{nan=‘男人‘,nv=‘女人‘,cen=‘中性人‘}
let arr1:number[ ] // 声明一个数值类型的数组
let arr3:Array<string> = [‘jack‘,‘tomy‘,‘gogo‘] // 声明一个字符串类型的数组
let arr3:Array<string> = new Array(‘jack‘,‘tomy胖‘,‘gogo‘) // 声明一个字符串类型的数组
①.返回可多种类型
function searchXiaoJieJie(age:number):string/void{
return ‘找到了‘+age+‘岁的小姐姐‘
}
var age:number = 18
var result:string = searchXiaoJieJie(age)
console.log(result)
②.可选参数的函数
function searchXiaoJieJie2(age:number,stature?:string):string{
if(stature !=undefined){
yy = yy + stature
}
}
③.有默认参数的函数
function searchXiaoJieJie2(age:number=18,stature:string=‘大长腿‘):string{
let yy:string = ‘‘
yy = ‘找到了‘+age+‘岁‘
if(stature !=undefined){
yy = yy + stature
}
return yy+‘的小姐姐‘
}
④.有剩余参数的函数
function searchXiaoJieJie3(...xuqiu:string[]):string{
let yy:string = ‘找到了‘
for (let i =0;i<xuqiu.length;i++){
yy = yy + xuqiu[i]
if(i<xuqiu.length){
yy=yy+‘、‘
}
}
yy=yy+‘的小姐姐‘
return yy
}
<br /><br />
let d:Date = new Date()
let d:Date = new Date(1000)
console.log(d) //1970-01-01T00:00:01.000Z
let d1:Date = new Date(‘2018/09/06 05:30:00‘)
let d2:Date = new Date(‘2018-09-06 05:30:00‘)
let d3:Date = new Date(‘2018-09-06T05:30:00‘)
console.log(d1)
console.log(d2)
console.log(d3)
let d:Date = new Date(year,month,day,hours,minutes,seconds,ms);
//构造函数法
let reg1:RegExp = new RegExp("jspang") //表示字符串规则里含有jspang
console.log(reg1)
let reg2:RegExp = new RegExp("jspang",‘gi‘)
console.log(reg2)
//字面量法
let reg3:RegExp = /jspang/
let reg4:RegExp = /jspang/gi
标签:ber any 变量 script 返回 ons i++ cond ret
原文地址:https://www.cnblogs.com/lgyong/p/13181954.html