美文网首页
Typescript第一篇

Typescript第一篇

作者: Nonb | 来源:发表于2019-03-01 17:44 被阅读0次

什么是typescript:

简单来说它是JavaScript的超集,它扩展了JavaScript的语法,所以任何现有的JavaScript程序可以不加改变的在TypeScript下工作。TypeScript是为大型应用之开发而设计,而编译时它产生 JavaScript 以确保兼容性

Typescript的优势

1:支持es6

2:强大的ide支持

3:Angular2框架的开发语言 据说vue3.0也全面改用typescript重写了

Typescript基础 字符串模板

1:自动拆分字符串:  

// ts字符串 console.log(`hello ${getname}`) 

// 编译js console.log("hello + getname")

function test(template,name,age){

    console.log(template)

    console.log(name)

    console.log(age)

}

var myname= "fu gang"

var getage = function () {

    return 18;

}

test `hello my name is ${myname}, i'm ${getage()}` 

2: 默认参数

`function test (a:string,b:string,c:string="jojo"){

    console.log(a)

    console.log(b)

    console.log(c)

}

test("xxx","yyy","zzz") // xxx yyy zzz

test("xxx","yyy") //xxx yyy jojo`

3:可选参数

function test (a:string,b?:string,c:string="jojo"){

    console.log(a)

    console.log(b)

    console.log(c)

}

test("xxx","","zzz") // xxx undefind zzz ?代表可选参数

test("xxx","yyy") //xxx yyy jojo

相关文章

网友评论

      本文标题:Typescript第一篇

      本文链接:https://www.haomeiwen.com/subject/fhcjuqtx.html