TypeScript随手
Typescript多构造函数
不支持多个构造函数,可以使用可选参数
1 2 3 4 5 6 7 8 9 10 | constructor(data?: IRefTeamSysMsgInfo) { if (data !== undefined) { this .id = data.id this .sendTime = data.sendTime this .msgType = data.msgType this .uid = data.uid this .state = data.status } } |
c#中Action在ts中实现,在ts中的变量都是undefine
c# 中
1 2 3 4 5 6 | public Action OnUpdate; void Update() { OnUpdate?.invoke(); } |
ts中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | export class Test{ beInit:boolean = false Init() { this .kcpHelper.OnUpdate= this .Update.bind( this ) } Update() { KcpLog.I(`KcpManager.Update0 ${ this .beInit} `) } } |
如果不加bind(this) 则beInit输出undefine
函数参数中的?
export function autodata(dataKeyName?: string, type: JsProxyDataType = JsProxyDataType.Auto) {。中dataKeyName?中的?是什么意思
在 TypeScript 中,?
表示参数是可选的,可以在函数调用时省略该参数
enum取全部选项value或key
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | enum ServerCommand { // Request UserLoginRequest = 1001, // Response UserLoginResponse = 2001, // Sync TeamMsgSync = 3001, // Sync Ack SyncAck = 4001, // HeartBeat HeartBeat = 5001, // HeartBeat 应答 HeartBeatAck = 5002, } const enumKeys = Object.keys(ServerCommand) as (keyof typeof ServerCommand)[]; enumKeys.forEach((key) => { console.log(key); }); const enumValues = Object.values(ServerCommand) as (keyof typeof ServerCommand)[]; enumKeys.forEach((value) => { console.log(value); }); |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 字符编码:从基础到乱码解决
2018-05-29 csdn地址备份