一:传统写法
// 定义: 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
标签:idate,05,1580646020000,handleDate,js,2024,resolveDate,date,new From: https://www.cnblogs.com/iuniko/p/18178643