![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
ts
先不要想收获,扎实
你的孤独,虽败犹荣
展开
-
初识(typescript)--ts //模块,命名空间,装饰器,例子(类,接口)
模块export(类,接口,变量,函数) :导出声明 default(默认)import:导入命名空间namespace : 定义一块私有的空间,恰好与export相反,外部看不到内部细节装饰器在类的上面@装饰器名称 : 不改变原有的类,动态扩展类的属性和方法function logclass (info : any){ console.log(info) info.prototype.apiurl = 'localhost:8080'}@logclassclass原创 2022-01-19 11:47:35 · 426 阅读 · 0 评论 -
初识(typescript)--ts //接口
接口:可用作约束多个对象,数组,函数关键字:interface//可选参数,对象的约束 interface peopleName{ fristName? : string, lastName? : string,} // 定义多个方法function teacher(name:peopleName) : void{ console.log(`语文老师叫: ${name.fristName} ${name.lastName}`);}function so原创 2022-01-17 13:58:56 · 480 阅读 · 0 评论 -
初识(typescript)--ts //多态,抽象
多态属于继承,是继承的一种延续在父类内部有一个公用方法,但是不知道具体做什么,由多个子类继承同一个方法,实现不同效果这个公用方法也叫方法的重写class Animall{ name:string; constructor(name:string){ this.name = name } eat():void{ }}class Dog extends Animall{ constructor(name : string){原创 2022-01-12 11:18:45 · 387 阅读 · 0 评论 -
初始(Javascript/Typescript) --ts/js 实例方法与静态方法
实例方法 与 静态方法js// 实例方法function Person(){ this.name = '张飞' run(){ return `${this.name}在救关羽` }}// 静态方法Person.work = function(){ //静态方法直接调用 return `${this.name}在保护刘备`}let A1 = new Person() //实例方法需要new一下tsclass Person{原创 2022-01-12 10:30:54 · 250 阅读 · 0 评论 -
初识(Typescript) -- ts //类,继承
定义类 class Person{ name:string; age:number; constructor(n:string , age :number){ this.name = n this.age = age } getName():string{ return this.name } setName(na原创 2022-01-12 10:01:16 · 467 阅读 · 0 评论 -
初识(typescript) -- ts //函数
函数: 声明函数 function run() :String { return '23' }: 匿名函数var run = function() :string{ return 'q2'} : 函数带参数 function run(A:string , B :number):string{ return `{A} -- {B}` }: 匿名函数带参let run =function (A:string , B :number):string{原创 2022-01-10 09:37:42 · 488 阅读 · 0 评论 -
初识(typescript) -- ts
下载安装/编译npm install -g typescriptcnpm install -g typescriptyarn global add typescript在控制台输入 tsc -v 可以看到版本号,则安装成功现阶段浏览器不支持ts语言需要转译为js在当前项目控制台输入 tsc – init 初始化生成tsconfig.json文件,在此配置文件’outDir’:’/.js’ ,将ts文件转到js文件项目内导航栏终端 》 运行任务 》 typescr.原创 2022-01-07 17:05:14 · 639 阅读 · 0 评论