![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Typescript
Tsurumure
热爱技术,喜欢技术交流,希望通过学习更多的技术,实现自我的商业价值
展开
-
Typescript学习笔记 - 装饰器 @(类,属性,方法)
普通装饰器 (无法传参)// 类装饰器function logClass(params:any) { params.prototype.apiUrl = 'xxx' params.prototype.run = function () { console.log('i am run!') }}@logClassclass HttpClient {...原创 2019-11-18 16:26:32 · 1125 阅读 · 0 评论 -
Typescript学习笔记 - 模块化export, import
简单示例./modules/db.tsvar dbUrl='xxxxxx'function getData():any[] { console.log('获取数据库的数据111') return [ { title:'121312' }, { title:'121312' } ]}function save() { console.log(...原创 2019-11-18 16:25:22 · 400 阅读 · 0 评论 -
Typescript学习笔记 - 泛型
与 :Any 类似, <T>, :T但 :any 放弃了类型检查我们想要实现:传入不同的类型返回不同的结果通俗理解:泛型就是解决 类 接口 方法的复用性对不特定数据类型的支持(类型校验)泛型函数// T 即泛型function GetData<T>(value:T):T { return value}console.log(GetData<...原创 2019-11-18 16:24:21 · 144 阅读 · 0 评论 -
Typescript学习笔记 - 接口 Interface
接口起到一种限制和规范的作用接口定义了某一批类所需要遵守的规范一个接口可以对多个方法进行约束接口可以继承类(类型)接口 (implements)和抽像类有点类似interface Animal { name:string; eat(str:string):void;}class Dog implements Animal { name:string; ...原创 2019-11-18 16:23:05 · 149 阅读 · 0 评论 -
Typescript学习笔记 - 类 (传参、继承super、多态)
ES5:function Person(name){ this.name=name; this.run = function () { alert(this.name + ' es5!') }}var p=new Person('张三');p.run()Typescript:class Person { name:string; // ...原创 2019-11-18 16:22:07 · 872 阅读 · 0 评论 -
Typescript学习笔记 - 方法 (静态Static、抽象Abstract)
构造方法:constructor() { … }实例方法:funName () { … }静态方法:static funName () { … }抽象方法/类:abstract class Per { … }静态方法(静态属性同理)// ES5function Person () {..}Person.run = function () {..}// 静态方法不需要实例化 new ...原创 2019-11-18 16:21:01 · 361 阅读 · 0 评论 -
Typescript学习笔记 - 函数参数
可选参数可选参数必须配置在必填参数的后面function fn (name?:string, age?:number):void { console.log(name || 'noBody')}fn() // noBodyfn('Tom') // Tom默认参数function fn (name?:string, age:number = 30):void { co...原创 2019-11-18 16:19:33 · 429 阅读 · 0 评论 -
Typescript学习笔记 - 数据类型
元组类型 tuple属于数组的一种,可以在同一个数组里面定义不同类型let arr:[number, string] = [123, 'abc']枚举类型 enum一般用于状态码判断emnu Status { 'error', 'success' }let s:Status = Status.successconsole.log(s) // 1任意类型 anyvar oBox...原创 2019-11-18 16:16:57 · 126 阅读 · 0 评论