摘要: 举例需求:在UI线程中新建一个线程用来加载资源,加载完成后通知UI线程 --定义类中的成员函数 function MainManager:loadResOver(info) cclog("loadResOver"..info) end --func1委托对象,加载完后通知传递进来的函数 functi 阅读全文
posted @ 2020-12-27 22:16 小翔momo 阅读(1431) 评论(0) 推荐(0) 编辑
摘要: //函数的合并 function reverse(x: number): number; function reverse(x: string): string; function reverse(x: number | string): number | string { if (typeof x 阅读全文
posted @ 2020-12-13 22:25 小翔momo 阅读(71) 评论(0) 推荐(0) 编辑
摘要: //简单例子function createArray<T>(length: number, value: T): Array<T> { let result: T[] = []; for (let i = 0; i < length; i++) { result[i] = value; } retu 阅读全文
posted @ 2020-12-13 21:59 小翔momo 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 抽象类里面可以有方法的实现,但是接口完全都是抽象的,不存在方法的实现; 子类只能继承一个抽象类,而接口可以被多个实现; 抽象方法可以是public,protected,但是接口只能是public,默认的; 抽象类可以有构造器,而接口不能有构造器; 抽象类当做父类,被继承。且抽象类的派生类的构造函数中 阅读全文
posted @ 2020-12-13 19:38 小翔momo 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 门是一个类,防盗门是门的子类。如果防盗门有一个报警器的功能,我们可以简单的给防盗门添加一个报警方法。这时候如果有另一个类,车,也有报警器的功能,就可以考虑把报警器提取出来,作为一个接口,防盗门和车都去实现它: interface Alarm { alert(): void; } class Door 阅读全文
posted @ 2020-12-13 19:29 小翔momo 阅读(80) 评论(0) 推荐(0) 编辑
摘要: class Animal{ public name; public constructor(name){ this.name = name; } } let a = new Animal('lx'); cc.log(a.name); //如果用private修饰就不能访问 a.name = 'hel 阅读全文
posted @ 2020-12-13 15:41 小翔momo 阅读(48) 评论(0) 推荐(0) 编辑
摘要: enum Lx{'hello', 'nice', 'good'}; cc.log(Lx['hello'] == 0) cc.log(Lx['nice'] == 1) cc.log(Lx['good'] == 2) cc.log(Lx[0]) 上面是枚举基本用法 //手动赋值枚举 enum Lx{bj 阅读全文
posted @ 2020-12-13 14:47 小翔momo 阅读(58) 评论(0) 推荐(0) 编辑
摘要: let tom: [string, number] = ['lx', 29]; tom[0] = 'haha'; tom[1] = 22; tom = ['nice', 18]; tom.push(2); tom.push(true); //当添加越界的元素时,它的类型会被限制为元组中每个类型的联合 阅读全文
posted @ 2020-12-13 14:08 小翔momo 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 1 type testName = 'lx' | 'bj' | 'cd' | 1; 2 3 function testFun(arg1: testName){ 4 5 } 6 testFun('lx'); //正确 7 testFun(1); //正确 8 testFun('ll'); //错误 阅读全文
posted @ 2020-12-13 13:40 小翔momo 阅读(193) 评论(0) 推荐(0) 编辑
摘要: type Name = string; function getName(n: Name): Name { if (typeof n 'string') { cc.log('is string'); } return n; } getName('12aa'); 类型别名用type来创建 阅读全文
posted @ 2020-12-13 13:10 小翔momo 阅读(85) 评论(0) 推荐(0) 编辑