摘要: UDP UDP是面向无连接的网络传输协议。通信都不需要,所以具有不可靠性。由于它的不可靠性,不用保证数据的有序完整,所以它又具有高效性。 TCP三次握手 客户端首先向服务端发送一个带有SYN的请求(第一次握手);服务端收到请求后返回带有SYN/ACK的响应(第二次握手);客户端收到响应后再返回一个带 阅读全文
posted @ 2021-11-12 08:08 webLion200 阅读(89) 评论(0) 推荐(0)
摘要: 泛型变量 function identity<T>(arg: T): T { return arg } function loggingIdentity<T>(arg: T[]): T[] { console.log(arg.length) return arg } 泛型函数 loggingIden 阅读全文
posted @ 2021-11-10 13:18 webLion200 阅读(51) 评论(0) 推荐(0)
摘要: as is as 是类型断言 let someValue: any = 'this is a string' let strLength: number = (someValue as string).length is 用于类型保护 function isString(test: any): te 阅读全文
posted @ 2021-11-10 13:18 webLion200 阅读(18) 评论(0) 推荐(0)
摘要: 函数类型 书写完整函数类型 函数类型包含两部分:参数类型和返回值类型。 let myAdd: (x: number, y: number) => number = function(x: number, y: number) { return x + y } 推断类型 在赋值语句的一边指定了类型但是 阅读全文
posted @ 2021-11-10 13:17 webLion200 阅读(23) 评论(0) 推荐(0)
摘要: 属性检查 类接口带有几个确定的属性,同时还会带有其他不确定的属性时,可如下定义: interface SquareConfig { color?: string width?: number [propName: string]: any } 使用类型断言(as)跳过检查 let mySquare 阅读全文
posted @ 2021-11-10 13:17 webLion200 阅读(30) 评论(0) 推荐(0)
摘要: 继承 class Animal { move(distance: number = 0) { console.log(`Animal moved ${distance}m.`) } } class Dog extends Animal { bark() { console.log('Woof! Wo 阅读全文
posted @ 2021-11-10 13:16 webLion200 阅读(46) 评论(0) 推荐(0)
摘要: 布尔值 let isDone: boolean = false 数字 let decLiteral: number = 20 let hexLiteral: number = 0x14 let binaryLiteral: number = 0b10100 let octalLiteral: num 阅读全文
posted @ 2021-11-10 13:15 webLion200 阅读(39) 评论(0) 推荐(0)
摘要: instanceof主要用于判断某个实例是否属于某个类型,也可用于判断某个实例是否是其父类型或者祖先类型的实例。 instanceof 主要的实现原理就是只要右边变量的 prototype 在左边变量的原型链上即可。因此,instanceof 在查找的过程中会遍历左边变量的原型链,直到找到右边变量的 阅读全文
posted @ 2019-02-12 22:50 webLion200 阅读(3264) 评论(0) 推荐(0)
摘要: 关键字new在调用构造函数的时候实际上进行了如下的几个步骤: 1. 创建一个新的对象 2. 将构造函数的作用域赋值给这个新的对象(因此this指向了这个新的对象) 3. 执行构造函数中的代码(为这个新对象添加属性) 4. 返回新对象 我们写一个函数,命名为objectFactory,来模拟new的效 阅读全文
posted @ 2019-02-12 13:37 webLion200 阅读(4315) 评论(0) 推荐(0)
摘要: call, apply, bind都是改变函数执行的上下文,说的直白点就是改变了函数this的指向。不同的是:call和apply改变了函数的this,并且执行了该函数,而bind是改变了函数的this,并返回一个函数,但不执行该函数。 看下面的 例子1: 由此可见,在stu上添加一个属性doThu 阅读全文
posted @ 2019-02-12 13:33 webLion200 阅读(2438) 评论(0) 推荐(0)