내용으로 건너뛰기
GaramX
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
home
»
javascript
»
class
추적:
•
typescript
javascript:class
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
===== class & this ===== IFEF을 활용하여 class를 구현함. ==== Class Source ==== <code javascript> 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("========"); </code> === output === <code> ======== 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 ======== </code>
javascript/class.txt
· 마지막으로 수정됨: 2025/04/15 10:05 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로