2024-05-07 js定义类的方法
一:传统写法
// 定义: function handleDate(date){ this.idate = new Date(date).getTime(); console.log(this.idate); this.resolveDate = function() { console.log('resolveDate',this.idate); } } // 使用: const getDate = new handleDate('2020-02-02 20:20:20'); getDate; // 1580646020000 this,handleDate = {idate: 1580646020000 } getDate; // 1580646020000 this,handleDate = {idate: 1580646020000 } 1580646020000
二:es6写法,es6引入了class,下面便是用class来定义类
// 定义: class handleDate2 { constructor(date) { this.idate = date; } resolveDate() { console.log(new Date(this.idate).getTime()); } } // 使用: const getDate2 = new handleDate2('2023-12-13 15:16:17' ); getDate2.resolveDate(); // 1702451777000
分类:
JavaScript
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
2022-05-07 2022-05-07 根据键值对来判断对象长度