• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Date] JS - prototype 속성(날짜) - 사용자정의 속성/메서드 추가 (날짜객체경우 = 프로토타입)

prototype 예제 - 날짜객체 경우

 

<button onclick="homzzang()">클릭</button>


<p id="demo"></p>


<script>

Date.prototype.monthToString = function() {

  if (this.getMonth() == 0){this.monthName = "1월"};

  if (this.getMonth() == 1){this.monthName = "2월"};

  if (this.getMonth() == 2){this.monthName = "3월"};

  if (this.getMonth() == 3){this.monthName = "4월"};

  if (this.getMonth() == 4){this.monthName = "5월"};

  if (this.getMonth() == 5){this.monthName = "6월"};

  if (this.getMonth() == 6){this.monthName = "7월"};

  if (this.getMonth() == 7){this.monthName = "8월"};

  if (this.getMonth() == 8){this.monthName = "9월"};

  if (this.getMonth() == 9){this.monthName = "10월"};

  if (this.getMonth() == 10){this.monthName = "11월"};

  if (this.getMonth() == 11){this.monthName = "12월"};

};


function homzzang() {

  var d = new Date();

  d.monthToString();

  document.getElementById("demo").innerHTML = d.monthName;

}

</script>

 

결과보기

결과값: August

※ monthToString 메서드와 monthName 속성은 사용자 정의값임.

 

방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
DOM JS - CSS - 스타일변경
DOM JS - Animation - 애니메이션 (= 동적효과 = 움직임효과)
DOM JS - Events - 이벤트 2
DOM JS - addEventListener() 메서드 ★★★★★ - 이벤트 걸기 (= addEventListen…
DOM JS - Navigation - 노드탐색 (= 요소탐색) ※ 텍스트노드복사
DOM JS - Node - 노드추가, 노드삭제, 노드변경 (= 노드생성, 노드제거, 노드교체)
DOM JS - Collection - HTML요소집합 (= HTML요소묶음)
BOM JS - Window BOM - 윈도우 브라우저객체모델 (BOM: Browser Object Model)
BOM JS - Window Screen 객체 - 화면객체 (= 스크린객체 = screen객체)
BOM JS - Window Location 객체 - 위치객체 (= 로케이션객체 = Location객체) ※ loc…
BOM JS - Window History 객체 - 이력객체 (= 히스토리객체 = History객체 = 뒤로가기 +…
BOM JS - Window Navigator 객체 - 브라우저객체 (= 네이게이터객체 = Navigator객체 =…
BOM JS - Popup Boxes - 팝업상자 (= 팝업박스 = Alert Box + Confirm box + …
BOM JS - Timing Events ★ - 시간간격 코드실행 (= 타이밍 이벤트 = 시간이벤트 = 일정시간별 …
BOM JS - Cookie (쿠키) 사용법 ★★★ - 쿠키 (설정・생성) / 쿠키 (읽기・얻기・가져오기) / 쿠…
AJAX JS - AJAX (아작스) 소개
AJAX JS - AJAX - XMLHttpRequest() 메서드 ★ - 객체생성 (= 아작스/에이잭스 핵심 = X…
AJAX JS - AJAX - open()/send() 메서드 ★ - 서버에 요청 보내기 (GET방식 vs POST방…
AJAX JS - AJAX - Server Response (서버응답) - 콜백함수 사용 예제
AJAX JS - AJAX - XML 아작스 예제 (= xml 데이터 불러와 표만들기)
4/67
목록
찾아주셔서 감사합니다. Since 2012