IFEF을 활용하여 class를 구현함.
var MyCalendar = /** @class */ (function () { function MyCalendar() { this.today = new Date(); this.cal = []; } MyCalendar.prototype.calculate = function () { return 100; }; MyCalendar.prototype.dateId = function (day) { var s; var m = day.getMonth() + 1; var d = day.getDate(); var sm = (m < 10 ? "0" : "") + m; s = day.getFullYear() + sm + (d < 10 ? "0" : "") + d; return s; }; MyCalendar.prototype.getCalendar = function (myStr) { if (myStr === void 0) { myStr = 'default'; } //var cal = []; var myDate = new Date(); var myCalen = this; for (var i = 0; i < 2; i++) { this.cal.push({ myString: function () { return myStr; }, date_id: this.dateId(myDate), isToday: function () { var date_id = myCalen.dateId(new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate())); console.log("isToday():this.date_id:" + this.date_id); console.log("isToday():date_id:" + date_id); return (myCalen.dateId(myCalen.today) === myCalen.dateId(this.date)); }, date: new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate(), 0, 0, 0), isCurWeek: function () { return myCalen.dateId(myCalen.today); } }); myDate.setDate(myDate.getDate() + 1); } }; return MyCalendar; }()); var myCal = new MyCalendar(); myCal.getCalendar(); console.log("========"); myCal.cal.forEach(function (val, idx) { console.log("forEach:" + idx + ":" + val.date_id + ":" + val.isToday()); console.log("isCurWeek:" + val.isCurWeek()); console.log("++++++++"); }); myCal.today.setMonth(3); console.log("--------"); myCal.cal.forEach(function (val, idx) { console.log("forEach:" + idx + ":" + val.date_id + ":" + val.isToday()); console.log("isCurWeek:" + val.isCurWeek()); }); console.log("========");
======== isToday():this.date_id:20190301 isToday():date_id:20190303 forEach:0:20190301:true isCurWeek:20190301 ++++++++ isToday():this.date_id:20190302 isToday():date_id:20190303 forEach:1:20190302:false isCurWeek:20190301 ++++++++ -------- isToday():this.date_id:20190301 isToday():date_id:20190303 forEach:0:20190301:false isCurWeek:20190401 isToday():this.date_id:20190302 isToday():date_id:20190303 forEach:1:20190302:false isCurWeek:20190401 ========